From c8a63cc71bf11dae6193a375082a96a272107933 Mon Sep 17 00:00:00 2001 From: genteure Date: Sat, 22 Jun 2024 22:22:06 +0800 Subject: [PATCH] feat: Improve error handling in DanmakuMergerHandler Also returns file name of the source of exception in error message. --- .../DanmakuMerger/DanmakuMergerHandler.cs | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/BililiveRecorder.ToolBox/Tool/DanmakuMerger/DanmakuMergerHandler.cs b/BililiveRecorder.ToolBox/Tool/DanmakuMerger/DanmakuMergerHandler.cs index 033f1e6..9da7cbf 100644 --- a/BililiveRecorder.ToolBox/Tool/DanmakuMerger/DanmakuMergerHandler.cs +++ b/BililiveRecorder.ToolBox/Tool/DanmakuMerger/DanmakuMergerHandler.cs @@ -174,7 +174,22 @@ namespace BililiveRecorder.ToolBox.Tool.DanmakuMerger for (var i = 0; i < inputLength; i++) { var r = readers[i]!; - var el = ReadDanmakuElement(r); + XElement? el = null; + + try + { + el = ReadDanmakuElement(r); + } + catch (Exception readEx) + { + return new CommandResponse + { + Status = ResponseStatus.InputIOError, + Exception = readEx, + ErrorMessage = request.Inputs[i] + ": " + readEx.Message + }; + } + if (el is null) { readers[i] = null; @@ -206,7 +221,23 @@ namespace BililiveRecorder.ToolBox.Tool.DanmakuMerger if (reader is not null) { readNextElementFromSameReader: - var newEl = ReadDanmakuElement(reader); + + XElement? newEl = null; + + try + { + newEl = ReadDanmakuElement(reader); + } + catch (Exception readEx) + { + return new CommandResponse + { + Status = ResponseStatus.InputIOError, + Exception = readEx, + ErrorMessage = request.Inputs[readerIndex] + ": " + readEx.Message + }; + } + if (newEl is null) { // 文件已结束