preserve diagnostic context on API, WebSocket, and auth failure paths - #14
Open
baseberry-uat[bot] wants to merge 1 commit into
Open
preserve diagnostic context on API, WebSocket, and auth failure paths#14baseberry-uat[bot] wants to merge 1 commit into
baseberry-uat[bot] wants to merge 1 commit into
Conversation
…paths Co-authored-by: baseberry-uat[bot] <227608112+baseberry-uat[bot]@users.noreply.github.com>
Author
|
Warning Polylane could not verify the production impact of this pull request. Checked all four error-path changes; this is a locally-installed CLI, not a deployed service, and every change is additive (same exit codes, same flow, more context in messages). No production resource runs this code. Polylane could not find the cloud resources this repository manages, so this review looked at the entire cloud account. Connect this repository to its resources and the next review will focus on exactly what this code deploys to. Polylane analysed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Generated by Polylane Autofix after
coreplanelabs/cliwas connected.Where this came from. Every step below links to the record behind it.
fix_fd392c…Four critical CLI paths were silently swallowing diagnostic context that an operator needs during an incident: API responses that aren't JSON, WebSocket closures, OAuth token refresh failures, and the credential resolver's fallback after a failed refresh. Each failure produced an error message stripped of the server's reason, the endpoint URL, or the WebSocket close code — leaving an operator to reproduce the failure manually with curl or network traces to learn what the server actually said.
Before / After
Before: When an API request returned a non-JSON body (e.g., a gateway HTML error page or a misconfigured domain), the error only said
Invalid JSON response from server (status 502)with no URL, method, or body. When an OAuth token refresh failed, the error saidToken refresh failed: 401with no server reason. When a WebSocket stream closed before a reply, the error saidWebSocket closed before replywith no close code. And when a token refresh failed silently inside the credential resolver, an operator running with--verbosesaw onlyNot authenticated— no trace that refresh was even attempted or why it failed. A missed-message incident or a stale-token auth loop had no diagnostic trail to point at the root cause; every failure required reproducing with manual curl or network traces to learn what the server actually said. After running--verbose, the refresh failure is now printed to stderr:Token refresh failed: Token refresh failed: 401 {invalid_grant}, telling the operator that a refresh was attempted and why it failed. Similarly, the API request error now prints the HTTP method, the endpoint URL, the status code, and the first 500 bytes of the response body; aWhat changed
src/client/http.ts:requestJsoncatch block now reads body as text first, then JSON.parses; error includes HTTP method, endpoint URL, status, and first 500 chars of response body (matching the body-snippet pattern fromthread-chat.ts:216). Added hint:Check --domain=${config.domain} and your network.Validation
npm run typecheck— passedRoot cause, safety reasoning, and scoping notes
Root cause
All four changes are surgical, additive, and mirror existing patterns in the codebase. No new dependencies, no schema changes, no config changes, no deploy-ordering concerns.
Why it's safe
All changes are additive: they preserve the existing error shape (CLIError with the same ExitCode) and only append new context. The
requestJsonchange reads the body as text first and JSON.parses it, matching the pattern already inthread-chat.ts:216— no new dependencies, no schema changes, no deploy ordering concerns. TheresolveCredentialverbose log goes to stderr only when--verboseis set, preserving the non-verbose UX.Out of scope / follow-ups
Skipped:
src/client/thread-chat.ts:201-203(parseSseChunks catch block silently drops malformed SSE chunks) — lower priority since valid chunks still finalize. Skipped:src/auth/oauth.tscallback server logging — interactive browser flow, already surfaces errors via CLIError.4 files changed (+21/-8)
src/auth/refresh.ts: modified, +2/-1src/auth/resolver.ts: modified, +6/-2src/client/http.ts: modified, +7/-3src/client/thread-chat.ts: modified, +6/-2Generated by Polylane.