Skip to content

Discard handler return value in exception handling to prevent polluting raw_response#309

Open
TheRealNeil wants to merge 1 commit intoactiveagents:mainfrom
qlarity:fix-handle-exception-method
Open

Discard handler return value in exception handling to prevent polluting raw_response#309
TheRealNeil wants to merge 1 commit intoactiveagents:mainfrom
qlarity:fix-handle-exception-method

Conversation

@TheRealNeil
Copy link
Contributor

@TheRealNeil TheRealNeil commented Feb 8, 2026

Discard handler return value in exception handling to prevent polluting raw_response

Fixes #305

Summary

  • Add explicit nil return after rescue_with_handler in with_exception_handling to prevent the handler's return value leaking into raw_response

Root cause

When an exception occurs during api_prompt_execute, with_exception_handling returns whatever the rescue handler returns (often a truthy value like a String from broadcast_error). This becomes raw_response in resolve_prompt, which then causes a secondary NoMethodError: undefined method 'usage' for an instance of String — swallowing the real error.

Fix

Return nil explicitly after rescue_with_handler(exception) || raise. This ensures raw_response is always nil when an exception has been handled, preventing the secondary error while still letting the agent's rescue_from chain handle the original exception.

Test plan

  • Trigger a provider exception with a rescue_from handler that returns a truthy value and confirm no secondary NoMethodError on usage
  • Confirm unhandled exceptions still re-raise as expected
  • Confirm rescue_from handlers are still invoked correctly

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.

with_exception_handling returns handler's value, polluting raw_response

1 participant