Repository navigation
fix(run-external): explain a missing shebang interpreter instead of showing an internal error - #19280
Conversation
When the executable exists but spawning it fails with "not found", the interpreter in its shebang line or a file it needs (such as a shared library) is missing. Say that, pointing at the command, instead of showing an internal error with a Rust source location.
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
The NotFound hint helps the case in #15970, but other spawn errors still show the Rust source line, the hint is wrong on Windows, and the message could name the interpreter the way bash, zsh and fish do.
Findings: 0
Open (6)
Other spawn errors still point at a Rust source line On Windows this blames a shebang that can't exist Name the interpreter, like bash, zsh and fish do The label shows what was typed, not what was run Test skips therun-externalprefix and the non-NotFound path Writing then executing a script in a threaded test can hit ETXTBSY on Linux
Notes from my clanker, checked on 55bbd05 by reading the branch; it wasn't built. The permission-denied and argument-list-too-long probes ran on nu 0.116.2, where those lines are the same as on the branch, and the fish, zsh and bash output came from macOS.
Cover the other spawn errors too: they now point at the command and its resolved path instead of a line of Rust code. For a "not found" error, name the interpreter from the shebang line when it is missing, otherwise point at a missing library or loader, keep the OS error text, and show which file was run. Only say this on Unix, and not if the file has since been removed. Tests cover all three call forms, a missing interpreter and one that isn't executable, and retry when Linux reports the freshly written script as busy.
|
Please reply to each review comment to ensure nothing is missed. |
There was a problem hiding this comment.
Review overview
🟡 Changes recommended
All six points from my last review are fixed. This is one small leftover from the new commit.
Findings: 0
Notes from my clanker, checked on 6098539. I built the branch and ran cargo test -p nu-command --test tests -- commands::run_external (74 passed). On macOS, the missing-interpreter, permission-denied, argument-list-too-long and stale-PATH-script cases each point at the command with the file path, and none of them show a Rust source line.
| @@ -543,6 +559,35 @@ fn write_pipeline_data( | |||
| } | |||
|
|
|||
| /// Returns a helpful error message given an invalid command name. | |||
There was a problem hiding this comment.
command_not_found lost its doc comment
start_failure_help went in between this line and pub fn command_not_found, so this line is now the first line of start_failure_help's doc, and command_not_found has no doc at all. The helper's doc reads "Returns a helpful error message given an invalid command name. Explains why an executable that exists could not be started...". Moving this line down to sit directly above pub fn command_not_found fixes both.
There was a problem hiding this comment.
I moved it back above command_not_found.
|
Thanks |



Description
Running a script whose shebang interpreter doesn't exist gave an internal error that pointed at a Rust source location:
By the time the child is spawned,
whichhas already found the executable, so on Unix a "not found" error from spawning means something the OS needs to start it is missing. Nushell now reads the first line of the file: if it starts with#!and that interpreter doesn't exist, the help names it, like bash, zsh and fish do. Otherwise it says a file the program needs (such as a shared library or its program loader) wasn't found, which is thelddcase in the issue. The help includes the resolved path, so it's clear which file was run:This hint is Unix-only and only used when the file still exists; on Windows, or when the file was removed after
whichfound it, you get the normal not-found error with the path. Other spawn errors (permission denied, argument list too long, exec format error) are now reported against the command and its path instead of a Rust source line.Tests in
crates/nu-command/tests/commands/run_external.rs(Unix only, for the bare,^andrun-externalforms):missing_shebang_interpreter_errornon_executable_shebang_interpreter_error(a#!pointing at a file that isn't executable, which now gives a permission error instead of the internal one)Both retry once if the run fails with
ExecutableFileBusy, to avoid the Linux "Text file busy" flake.User-facing changes (Release notes)
Additional notes
Fixes #15970
Tests + formatting:
cargo fmt --all -- --checkcargo clippy -p nu-config -p nu-cmd-lang -p nu-command -p nu-cli -p nu-explore --all-targets -- -D warnings -D clippy::unwrap_usedcargo test -p nu-command --test tests -- commands::run_external