Skip to content

Preserve exception chains with raise ... from - #3312

Open
syahra712 wants to merge 1 commit into
modelcontextprotocol:mainfrom
syahra712:fix/raise-from-exception-chaining
Open

Preserve exception chains with raise ... from#3312
syahra712 wants to merge 1 commit into
modelcontextprotocol:mainfrom
syahra712:fix/raise-from-exception-chaining

Conversation

@syahra712

Copy link
Copy Markdown

Summary

  • Adds from clause to 11 raise statements that catch one exception and raise another, preserving the original traceback and __cause__
  • Without from, Python shows "During handling of the above exception, another exception occurred" instead of "The above exception was the direct cause of the following exception", and callers cannot inspect __cause__ to determine the root cause programmatically
  • Follows the pattern established in fix: chain exceptions in get_prompt and read_resource handlers #2542 for the remaining sites

Files changed

File Change
client/session.py SchemaErrorRuntimeError
client/auth/utils.py ValidationErrorOAuthTokenError
server/auth/middleware/client_auth.py ValueError/UnicodeDecodeError/binascii.ErrorAuthenticationError
server/mcpserver/resources/types.py ExceptionValueError (4 sites)
server/mcpserver/server.py ResourceNotFoundErrorMCPError, ResourceErrorMCPError
server/mcpserver/prompts/base.py ExceptionValueError

Related issue

Fixes #2564

Verification

Add `from` clause to 11 raise statements that re-raise a new
exception after catching another, preserving the original traceback
and __cause__ for debugging.

Follows the pattern established in modelcontextprotocol#2542 for the remaining sites.

Fixes modelcontextprotocol#2564

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 6 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

raise without from discards exception chain in 12 remaining sites

1 participant