Dev/errors - #246
Conversation
There was a problem hiding this comment.
Code Review
This pull request improves error handling, parsing, and resilience across various API clients and protocols, including adding transient error retries with backoff in AsynchronousApi, extracting structured error codes and messages from JSON/non-JSON responses, and standardizing error types using the ErrorType enum. The review feedback highlights a potential NullPointerException in DashScopeResult due to auto-unboxing of a nullable Integer status code, suggests preserving a fallback error message in AgentStudioEventStream when the response body is empty, and recommends properly handling InterruptedException in AsynchronousApi instead of swallowing it.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Add AgentStudioException that converges error codes onto PublicErrorDef
(the single source of truth shared with the Python SDK). getCode()
returns the unified Anthropic-compatible code (rewriting legacy aliases
like permission_denied_error, mapping PascalCase server codes via
PublicErrorDef.fromErrorCode, and falling back to the per-status row
when the server omits one); the raw server code stays on getRawCode().
Default messages come from the registry with {var} placeholders stripped.
AsyncHelper wraps ApiException as AgentStudioException at the source so
all consumers see the unified type; joinAndUnwrap just unwraps the
CompletionException shell.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Fix CI linter (google-java-format-1.7) failures on the previous commit. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Internal sdk.agentstudio.* codes now surface only where PublicErrorCode has no equivalent: NETWORK (no HTTP response), CONFLICT (409), and UNKNOWN (unmapped non-5xx). Every other category resolves to a public code — mapped statuses via STATUS_TO_PUBLIC (now including 413), and any other 5xx via the generic api_error. KIND_TO_INTERNAL and InternalErrorCode are trimmed to the three reachable codes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The 9-value Kind enum + classify() + KIND_TO_INTERNAL duplicated the status dispatch already in STATUS_TO_PUBLIC, and 6 of its 9 values did nothing for code resolution. Remove all three. unifyCode now resolves through two symmetric tables — STATUS_TO_PUBLIC and a new STATUS_TO_INTERNAL (-1 -> NetworkError, 409 -> Conflict) — plus a >= 500 range fallback (unmapped 5xx -> public api_error, else internal UnknownError). This mirrors how the Python SDK dispatches by status table. getMessage() uses getCode() for its label and the public getKind() accessor is dropped; the two test assertions on it are removed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Each error path owns one code namespace: StatusError carries a public Anthropic-compatible code (the recognized server code, else generic api_error), while ConnectionError/StreamError carry sdk.agentstudio.* internal codes. A status error no longer guesses a public code from the HTTP status number. Server codes are recognized via the registry only; the unverified legacy permission_denied_error alias is dropped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Each error path owns one code namespace: StatusError carries a public Anthropic-compatible code (the recognized server code, else generic api_error), while ConnectionError/StreamError carry sdk.agentstudio.* internal codes. A status error no longer guesses a public code from the HTTP status number. Server codes are recognized via the registry only; the unverified legacy permission_denied_error alias is dropped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
# Conflicts: # src/main/java/com/alibaba/dashscope/agentstudio/resource/AgentStudioEventStream.java
| import java.util.Map; | ||
|
|
||
| /** Internal error codes with two-layer message design. */ | ||
| public enum InternalErrorCode { |
There was a problem hiding this comment.
丢了很多:
SDK_INVALID_API_KEY
SDK_AGENTIC_RL_xxx
# Conflicts: # src/main/java/com/alibaba/dashscope/protocol/okhttp/OkHttpWebSocketClient.java
The merge kept the dev/errors 503 SERVICE_UNAVAILABLE status for exhausted handshake retries, but main's #257 reverted to the fixed websocket failure status code 44 because callers rely on it. Restore the reverted behavior so TestFullDuplexErrorHandling passes.
… handshake retries The fixed status code 44 was restored on main for existing online users, but this branch is a future release and the status change will be announced. Switch back to SERVICE_UNAVAILABLE and update the handshake retry tests accordingly.
No description provided.