shell(cd): report ENOENT as 'no such file or directory', not 'not a directory'

Closed
RO
2mo ago
+26-2

What

Bun Shell's cd builtin reports a nonexistent directory as not a directory, which actively points debugging at the wrong cause (it implies the path exists but is a file).

import { $ } from "bun";
const r = await $`cd /definitely/not/here`.throws(false).quiet();
console.log(r.exitCode, JSON.stringify(r.stderr.toString()));
// -> 1 "cd: not a directory: /definitely/not/here\n"

bash: cd: /definitely/not/here: No such file or directory
zsh: cd: no such file or directory: /definitely/not/here

Cause

handle_change_cwd_err in src/runtime/shell/builtin/cd.rs collapses E::ENOTDIR | E::ENOENT into a single match arm that formats "not a directory: {}".

Fix

Split the arm: ENOENT -> no such file or directory: <path>, ENOTDIR keeps not a directory: <path>. Matches the existing lowercase style used for cd's other diagnostics (file name too long, too many arguments) and zsh's wording.

Verification

New test in the cd & pwd block of test/js/bun/shell/bunshell.test.ts asserts both messages: cd <missing> -> no such file or directory, cd <regular file> -> not a directory. Fails on the released build with cd: not a directory: ..., passes with this change.


no test proof · iteration 1 · Platform-specific test(s) that do not run on this machine. Deferring to CI, which covers all platforms: test/js/bun/shell/bunshell.test.ts