Repository navigation
fix(cli): show help when the directory argument doesn't exist - #65262
Conversation
There was a problem hiding this comment.
Looks good. I reproduced the raw ENOENT/ENOTDIR chdir stack trace on the base with opencode login and with a file passed as the directory. With this PR, both print the root help plus No directory or command named "…" and exit 1. A valid directory still gets past the check and starts as before.
Public API: unchanged. The only user-visible change is the error output for an invalid directory argument; the exit code stays 1.
The fix itself is small. The new test file spawns the full CLI twice (about 5s) and isn't needed for a change this size, so it can be dropped, or cut down to just the missing-directory case.
The directory is still checked locally even when --server is given (#47665). That is unchanged from before and out of scope here.
Issue for this PR
Closes #
Type of change
What does this PR do?
opencode <arg>treats an unknown positional as the directory to start in, so a mistyped or missing command likeopencode logincrashed with a rawENOENT: no such file or directory, chdir ... -> 'login'stack trace.The default handler now stats the directory argument before
chdir. If it's missing or isn't a directory, it fails with Effect CLI'sShowHelpcarrying aValidationError, so the runner prints the root help followed by:and exits 1. Valid directories behave as before.
How did you verify your code works?
bun run src/index.ts loginandbun run src/index.ts /path/to/a/fileboth print root help plus the error, exit 1packages/cli/test/default-directory.test.tscovers both cases; it fails without the fix and passes with itbun run typecheckinpackages/cliScreenshots / recordings
N/A (CLI output shown above)
Checklist
Requested by: @rekram1-node (Aiden Cline via Slack)
Added by the opencode bot (AI-generated).
Fixes #49663
Related: #47665