fix: format CliError/ArgumentError instead of leaking a raw stack trace in web fetch - #281
Open
Agnik47 wants to merge 1 commit into
Open
fix: format CliError/ArgumentError instead of leaking a raw stack trace in web fetch#281Agnik47 wants to merge 1 commit into
Agnik47 wants to merge 1 commit into
Conversation
…ce in web fetch runClientOwnedWebFetch runs on the client-owned fast path in main.ts, outside the try/catch every other command routes through in commanderAdapter.ts. Any CliError it threw (e.g. FETCH_BLOCKED) or ArgumentError from clientOptions() escaped straight to Node's default uncaught-exception handler instead of the structured error envelope the rest of the CLI uses. Fixes agentrhq#246
Contributor
🟢 No documentation gap found — medium confidenceThe automated review found no documentation gap in the supplied changes. This review is advisory and does not block merging. |
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.
Description
webcmd web fetchis dispatched on the client-owned fast path insrc/main.ts(argv[0] === 'web' && argv[1] === 'fetch'), before adapter discovery and before the hosted-mode branch, which callsrunClientOwnedWebFetchdirectly. That function (src/fetch/command.ts) had no try/catch, and the call site is outside theCliErrorhandling every other command routes through incommanderAdapter.ts. Any thrownCliError(e.g.FETCH_BLOCKED) orArgumentErrorfromclientOptions()therefore escaped straight to Node's default uncaught-exception handler as a raw stack trace, instead of the structured error output the rest of the CLI produces.Before
After
Same shape as any other command's error — verified by reproducing a real command's
CliErrorthrough the normalcommanderAdapter.tspath and comparing the envelope byte-for-byte with what this fix now produces on the fast path.Fix
Wrapped the body of
runClientOwnedWebFetchin a try/catch. On error, it now builds the sameErrorEnvelope(toEnvelope) and renders it with the sameformatErrorEnvelopeused bycommanderAdapter.ts, writes to stderr, and setsprocess.exitCodefromerr.exitCodewhen it's aCliError(falling back toEXIT_CODES.GENERIC_ERRORotherwise) — matchingresolveExitCode's behavior.output.jsis imported dynamically inside the catch block so the happy path (the common case) doesn't pay forcli-table3/js-yamlon this fast path.This covers both cases called out in the issue: a
CliErrorthrown from deep insidewebFetch()(e.g.FETCH_BLOCKED), and anArgumentErrorthrown synchronously byclientOptions()for bad flags.Fixes #246
Type of Change
Checklist
Screenshots / Output
npm run typecheckandnpm run buildpass, generated artifacts stay byte-identical (git diff --exit-codeclean after build).Added two regression tests to
src/fetch/command.test.ts(mockedwebFetch/clientOptions, no real network calls) covering theCliErrorandArgumentErrorpaths:Full
src/fetch/suite also passes (22/22).