Skip to content

Surface underlying cause in Anthropic API error reporting - #1450

Open
nancodex wants to merge 1 commit into
apache:mainfrom
nancodex:fix/anthropic-error-cause-propagation
Open

nancodex wants to merge 1 commit into
apache:mainfrom
nancodex:fix/anthropic-error-cause-propagation

Conversation

@nancodex

Copy link
Copy Markdown

Linked issue: None

Purpose of change

When an Anthropic API call fails, the error reported to the user contains only a static string ("Failed to call Anthropic messages API.") with no diagnostic information. Any API failure — timeout, auth error, invalid model, network issue — is reported as the same opaque string, making diagnosis impossible without reading the full TaskManager stack trace.

Root cause:

  • AnthropicChatModelConnection.chat() wraps all exceptions in RuntimeException("Failed to call Anthropic messages API.", e) — the cause e is attached but not surfaced.
  • ChatModelInvoker.errorText() extracts only getMessage(), discarding the cause entirely.

Behavioral Semantics

The change is backward compatible:

  • The original message substring "Failed to call Anthropic messages API." is preserved (existing testBuildFailureIsWrapped still passes).
  • The cause message is appended after "Cause: " in AnthropicChatModelConnection.chat().
  • ChatModelInvoker.errorText() appends [caused by: <cause>] when the exception has a non-null cause whose message is not already contained in the wrapper message.
  • No behavioral change for InvocationFailure or RoutingFailure — their messages are still returned as-is.

Tests

  • New test testChatExceptionIncludesCauseMessage verifies the wrapped RuntimeException includes "Cause:" and the root cause message.
  • Existing testBuildFailureIsWrapped continues to pass (original message substring preserved).
  • All 105 AnthropicChatModelConnectionTest tests pass.
  • All 14 ChatModelInvokerTest tests pass.

API

No public API changes. The errorText() method in ChatModelInvoker is public static but only the error string format changes (appends cause info), not the method signature.

Documentation

  • doc-needed
  • doc-not-needed
  • doc-included

Was this patch authored or co-authored using generative AI tooling?

  • Yes
  • No

Generated-by: Claude Code (Claude Sonnet 4)

@github-actions github-actions Bot added doc-not-needed Your PR changes do not impact docs fixVersion/1.0.0 The feature or bug should be implemented/fixed in the 1.0.0 version. priority/major Default priority of the PR or issue. labels Nov 25, 2026
@nancodex
nancodex force-pushed the fix/anthropic-error-cause-propagation branch 2 times, most recently from 5072017 to f6f0726 Compare November 25, 2026 06:06
When an Anthropic API call fails, the error reported to the user contains
only a static string with no diagnostic information. Any API failure —
timeout, auth error, invalid model, network issue — is reported as the
same opaque string.

AnthropicChatModelConnection.chat() wraps all exceptions in
RuntimeException with the cause attached, but ChatModelInvoker.errorText()
extracts only getMessage(), discarding the cause.

This change:
- Includes the cause message in the wrapper RuntimeException
- Appends the cause chain in ChatModelInvoker.errorText() when present

Generated-by: Claude Code (Claude Sonnet 4)
@nancodex
nancodex force-pushed the fix/anthropic-error-cause-propagation branch from f6f0726 to b65116d Compare November 25, 2026 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs fixVersion/1.0.0 The feature or bug should be implemented/fixed in the 1.0.0 version. priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant