fix(cosh): report API errors in all output formats, not only text#801
Open
jfeng18 wants to merge 1 commit into
Open
fix(cosh): report API errors in all output formats, not only text#801jfeng18 wants to merge 1 commit into
jfeng18 wants to merge 1 commit into
Conversation
In non-interactive mode (`cosh -p`), API error events (401, 429, etc.)
were only detected and reported when `outputFormat === OutputFormat.TEXT`.
In JSON and STREAM_JSON modes the error was silently consumed as normal
text content, emitted with `isError: false`, and the process exited 0 —
giving programmatic callers zero indication of failure.
Remove the TEXT-mode guard so error events throw in all output formats.
The existing catch block already correctly calls `adapter.emitResult({
isError: true, errorMessage })` for all formats, so the fix is a single
condition removal.
Adds two discriminating tests (JSON + STREAM_JSON) that verify:
- The error propagates (throw)
- stderr receives the error message (not silently swallowed)
Existing 28 tests continue to pass (TEXT mode behavior unchanged).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
dd7684e to
5016ab5
Compare
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
In non-interactive mode (
cosh -p), API error events (401, 429, etc.) were silently swallowed in JSON and STREAM_JSON output formats —isError: false, exit 0, empty stderr. Programmatic callers had zero indication of failure.Root Cause
nonInteractiveCli.ts:284gated error detection onoutputFormat === OutputFormat.TEXT. In JSON/STREAM_JSON modes, theGeminiEventType.Errorevent was consumed byadapter.processEvent()as normal text content, the loop finished normally, andemitResult({isError: false})was called.Fix
Remove the
outputFormat === OutputFormat.TEXT &&condition (one line). Error events now throw in all output formats. The existing catch block already correctly callsadapter.emitResult({isError: true, errorMessage})for all formats — it just was never reached in JSON/STREAM_JSON mode.TEXT mode behavior is unchanged (still writes to stderr + exit 1, as before).
Testing
Impact
isError: false, exit 0isError: true, exit 1isError: false, exit 0isError: true, exit 1🤖 Generated with Claude Code