mirror of
https://github.com/langgenius/dify.git
synced 2026-09-21 05:11:22 +08:00
fix(api): chain original exception in 13 except blocks per PEP 3134 (#40738)
Co-authored-by: Harsh Kashyap <Harsh23Kashyap@users.noreply.github.com>
This commit is contained in:
co-authored by
Harsh Kashyap
parent
c9c7fb9962
commit
8238684334
@@ -270,8 +270,8 @@ class PluginAppBackwardsInvocation(BaseBackwardsInvocation):
|
||||
app = session.scalar(select(App).where(App.id == app_id, App.tenant_id == tenant_id).limit(1))
|
||||
if app:
|
||||
session.expunge(app)
|
||||
except Exception:
|
||||
raise ValueError("app not found")
|
||||
except Exception as e:
|
||||
raise ValueError("app not found") from e
|
||||
|
||||
if not app:
|
||||
raise ValueError("app not found")
|
||||
|
||||
@@ -241,8 +241,10 @@ def cast_parameter_value(typ: StrEnum, value: Any, /):
|
||||
return str(value)
|
||||
except ValueError:
|
||||
raise
|
||||
except Exception:
|
||||
raise ValueError(f"The tool parameter value {repr(value)} is not in correct type of {as_normal_type(typ)}.")
|
||||
except Exception as e:
|
||||
raise ValueError(
|
||||
f"The tool parameter value {repr(value)} is not in correct type of {as_normal_type(typ)}."
|
||||
) from e
|
||||
|
||||
|
||||
def init_frontend_parameter(rule: PluginParameter, type: StrEnum, value: Any):
|
||||
|
||||
@@ -276,19 +276,19 @@ class BasePluginClient:
|
||||
json_response = transformer(json_response)
|
||||
# https://stackoverflow.com/questions/59634937/variable-foo-class-is-not-valid-as-type-but-why
|
||||
rep = PluginDaemonBasicResponse[type_].model_validate(json_response) # type: ignore
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
msg = (
|
||||
f"Failed to parse response from plugin daemon to PluginDaemonBasicResponse [{str(type_.__name__)}],"
|
||||
f" url: {path}"
|
||||
)
|
||||
logger.exception(msg)
|
||||
raise ValueError(msg)
|
||||
raise ValueError(msg) from e
|
||||
|
||||
if rep.code != 0:
|
||||
try:
|
||||
error = PluginDaemonError.model_validate(json.loads(rep.message))
|
||||
except Exception:
|
||||
raise ValueError(f"{rep.message}, code: {rep.code}")
|
||||
except Exception as e:
|
||||
raise ValueError(f"{rep.message}, code: {rep.code}") from e
|
||||
|
||||
self._handle_plugin_daemon_error(error.error_type, error.message)
|
||||
if rep.data is None:
|
||||
|
||||
@@ -19,5 +19,5 @@ class StructuredChatOutputParser:
|
||||
return ReactAction(response["action"], response.get("action_input", {}), text)
|
||||
else:
|
||||
return ReactFinish({"output": text}, text)
|
||||
except Exception:
|
||||
raise ValueError(f"Could not parse LLM output: {text}")
|
||||
except Exception as e:
|
||||
raise ValueError(f"Could not parse LLM output: {text}") from e
|
||||
|
||||
Reference in New Issue
Block a user