feat: Improve error handling in DanmakuMergerHandler

Also returns file name of the source of exception in error message.
This commit is contained in:
genteure 2024-06-22 22:22:06 +08:00
parent c428086ccb
commit c8a63cc71b

View File

@ -174,7 +174,22 @@ namespace BililiveRecorder.ToolBox.Tool.DanmakuMerger
for (var i = 0; i < inputLength; i++) for (var i = 0; i < inputLength; i++)
{ {
var r = readers[i]!; var r = readers[i]!;
var el = ReadDanmakuElement(r); XElement? el = null;
try
{
el = ReadDanmakuElement(r);
}
catch (Exception readEx)
{
return new CommandResponse<DanmakuMergerResponse>
{
Status = ResponseStatus.InputIOError,
Exception = readEx,
ErrorMessage = request.Inputs[i] + ": " + readEx.Message
};
}
if (el is null) if (el is null)
{ {
readers[i] = null; readers[i] = null;
@ -206,7 +221,23 @@ namespace BililiveRecorder.ToolBox.Tool.DanmakuMerger
if (reader is not null) if (reader is not null)
{ {
readNextElementFromSameReader: readNextElementFromSameReader:
var newEl = ReadDanmakuElement(reader);
XElement? newEl = null;
try
{
newEl = ReadDanmakuElement(reader);
}
catch (Exception readEx)
{
return new CommandResponse<DanmakuMergerResponse>
{
Status = ResponseStatus.InputIOError,
Exception = readEx,
ErrorMessage = request.Inputs[readerIndex] + ": " + readEx.Message
};
}
if (newEl is null) if (newEl is null)
{ {
// 文件已结束 // 文件已结束