Uh oh!
There was an error while loading. Please reload this page.
fix(opencode): surface usage errors instead of only printing help - #31799
fix(opencode): surface usage errors instead of only printing help#31799IbrahimKhan12 wants to merge 1 commit into
Conversation
The yargs .fail() handler printed help text for usage errors (unknown argument, missing positional, invalid values) but never wrote the error message yargs passes in, so `opencode --badflag` was indistinguishable from `opencode --help`. Write the message to stderr after the help so the user sees what was wrong; exit code stays 1.
The following comment was made by an LLM, it may be inaccurate: Potential Duplicates FoundI found 2 related open/recent PRs addressing the same issue:
All three PRs (including the current PR #31799) address the same problem: the |
Issue for this PR
Closes#29390
Type of change
What does this PR do?
The yargs
.fail()handler inpackages/opencode/src/index.tsprinted help text for usage errors (unknown argument, missing positional, invalid values) but never wrote themsgthat yargs passes in. As a resultopencode --badflagproduced output identical toopencode --help, leaving the user with no indication their argument was wrong. The handler now writes the message to stderr (viaUI.error) after showing help, so the error appears at the bottom where it's visible. Exit code stays 1.How did you verify your code works?
Added a regression test at
packages/opencode/test/cli/fail-handler.test.tsusing the existing CLI subprocess harness: it spawnsopencode --this-flag-does-not-existand asserts exit code 1 and that stderr containsUnknown argument. The test fails on the current code and passes with the fix. Also verified manually: before, the command printed only help; after, it ends withError: Unknown arguments: ....oxlinton the changed files andtsgo --noEmit(bun run typecheck) for theopencodepackage are both clean.Screenshots / recordings
N/A (CLI stderr text change).
Checklist