Skip to content

fix(api): fix fail branch functionality for WorkflowTool #15966

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Conversation

QuantumGhost
Copy link
Collaborator

Summary

Previously, WorkflowTool._invoke raised an exception of type
Exception when the invoked tool encountered an error. This exception
was not properly caught by the caller, resulting in the API returning
an internal server error to the user.

This commit replaces the generic Exception with a specific
ToolInvokeError and ensures it is caught during message transformation
in the ToolNode. This converts the tool invocation failure into a NodeRunResult
event with a FAILED status, enabling the GraphEngine to correctly execute
the fail branch logic for error handling.
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Closes #15252.

Screenshots

Before After
image image

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

Previously, `WorkflowTool._invoke` raised an exception of type
`Exception` when the invoked tool encountered an error. This exception
was not properly caught by the caller, resulting in the API returning
an `internal server error` to the user.

This commit replaces the generic `Exception` with a specific
`ToolInvokeError` and ensures it is caught during message transformation
in the `ToolNode`. This converts the tool invocation failure into a `NodeRunResult`
event with a `FAILED` status, enabling the `GraphEngine` to correctly execute
the fail branch logic for error handling.
@QuantumGhost QuantumGhost requested a review from laipz8200 March 17, 2025 03:33
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 🐞 bug Something isn't working labels Mar 17, 2025
- Add a test case to verify `ToolNode` correctly catches `ToolInvokeError`
  during message transformation
- Add a test case to ensure `WorkflowTool` properly throws `ToolInvokeError`
  when workflow execution fails
@QuantumGhost QuantumGhost force-pushed the fix/workflow-tool-on-failure/try-catch-approach branch from 1780f91 to b0fdcd6 Compare March 17, 2025 03:48
Copy link
Member

@laipz8200 laipz8200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 17, 2025
@laipz8200 laipz8200 merged commit 2b4d1cf into langgenius:main Mar 17, 2025
6 checks passed
@QuantumGhost QuantumGhost deleted the fix/workflow-tool-on-failure/try-catch-approach branch March 27, 2025 03:14
parambharat pushed a commit to parambharat/dify that referenced this pull request Mar 31, 2025
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
🐞 bug Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Workflow exception capture fails
2 participants