From 4ef297bf3845cec7b7fb98f1bef5573690a9c094 Mon Sep 17 00:00:00 2001 From: QuantumGhost Date: Fri, 11 Apr 2025 17:32:20 +0800 Subject: [PATCH] refactor(api): Enhance error handling in BasePluginManager (#17887) --- api/core/plugin/manager/base.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/api/core/plugin/manager/base.py b/api/core/plugin/manager/base.py index ea6b338725..4b364d15c6 100644 --- a/api/core/plugin/manager/base.py +++ b/api/core/plugin/manager/base.py @@ -170,13 +170,16 @@ class BasePluginManager: for line in self._stream_request(method, path, params, headers, data, files): try: rep = PluginDaemonBasicResponse[type].model_validate_json(line) # type: ignore - except Exception: + except (ValueError, TypeError): # TODO modify this when line_data has code and message try: line_data = json.loads(line) - raise ValueError(line_data["error"]) - except Exception: + except (ValueError, TypeError): raise ValueError(line) + # If the dictionary contains the `error` key, use its value as the argument + # for `ValueError`. + # Otherwise, use the `line` to provide better contextual information about the error. + raise ValueError(line_data.get("error", line)) if rep.code != 0: if rep.code == -500: