Commit graph

1 commit

Author SHA1 Message Date
robopipi[bot]
88ffcdc734
fix(coding-agent): report a deleted working directory instead of crashing on startup (#11511)
Starting `pi` from a directory that has been deleted crashed with an
uncaught Node `ENOENT ... uv_cwd` stack trace. This also happened for
`--version` and `--help`. The cause is the unguarded `process.cwd()`
call in `main()` (`packages/coding-agent/src/main.ts`).

`main()` now catches `ENOENT` from that call, prints one line telling
the user to change to an existing directory, and exits with code 1.
Other errors are rethrown unchanged. Argument handling is otherwise
unchanged: `--version` still needs a valid cwd, but it now gets the
readable error instead of a crash.

**Testing**
- Added `test/deleted-cwd.test.ts`. It stubs `process.cwd()` to throw
ENOENT and checks that `main()` prints the message and exits with code
1. It also checks that a non-ENOENT error is rethrown. The first test
fails without the change and passes with it.
- `npm run check` passes.
- Manual check with the built CLI. Before, all three commands below
printed the `uv_cwd` stack trace. After, each prints `Error: The current
working directory no longer exists. Change to an existing directory and
try again.` and exits 1:
  ```sh
  d=$(mktemp -d); cd "$d"; rmdir "$d"
  pi -ne --version; pi -ne --help; pi -ne
  ```

Fixes #11509

Requested by @badlogic

Co-authored-by: triagent <triagent@localhost>
2026-10-28 09:51:39 +01:00