fix(auth): preserve typed API error envelope when setup key verification fails#38
Open
lxcario wants to merge 1 commit into
Open
fix(auth): preserve typed API error envelope when setup key verification fails#38lxcario wants to merge 1 commit into
lxcario wants to merge 1 commit into
Conversation
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.
What
When
setup --from-env --output jsonverifies an API key and the key is rejected (e.g. invalid or revoked), the JSON output is a bare{"error":"...string..."}instead of the typed envelope withcode,nextAction,requestId, anddetails.Why this matters
Machine consumers (coding agents, CI scripts) that
JSON.parse(stderr)expect the typed envelope shape documented in DOCUMENTATION.md. A bare string error gives them nocodeto branch on, nonextActionto surface, and norequestIdfor support. Every other API error path in the CLI already emits the full typed envelope; this is the sole exception.Reproduction
Root cause
src/commands/auth.ts,runConfigure, line 157-168. The key-verification catch block wraps the originalApiErrorin aCLIError:CLIErrorhas onlymessageandexitCode. Inindex.ts, theCLIErrorpath renders viaoutput.error(err.message)which produces{"error":"...string..."}-- losing the full typed envelope that theApiErrorpath would have rendered.Fix
When
erris anApiError, augment its.messagewith the endpoint context (so text-mode users still see which host rejected them), then re-throw it directly. TheApiErrorcatch path inindex.tsrenders the full typed envelope. Non-ApiErrorthrows (truly unexpected errors) still wrap inCLIErrorfor a clean exit 3.This mirrors how every other command path that catches and re-throws API errors already works (the error carries its own envelope; the CLI just sets exit code from it).
Tests
Added 1 regression test to
src/commands/auth.test.tsasserting the thrown error is anApiErrorwithcode: 'AUTH_INVALID',exitCode: 3,nextAction, andrequestIdintact. Fails onmainbefore this fix; passes after.main):Tests 16 failed | 1359 passed | 72 skippedTests 16 failed | 1360 passed | 72 skipped(+1 new test)The 16 failures are pre-existing and environment-specific (Windows path/line-ending), unrelated -- see #4.
Verification
npm test: same 16 pre-existing (environment-specific) failures as baseline, zero newnpm run typecheck: passnpm run lint: pass