Skip to content

fix(run-external): explain a missing shebang interpreter instead of showing an internal error - #19280

Merged
fdncred merged 3 commits into
nushell:mainfrom
qodelicious:fix-shebang-not-found-error
Oct 19, 2026
Merged

fdncred merged 3 commits into
nushell:mainfrom
qodelicious:fix-shebang-not-found-error

Conversation

@qodelicious

@qodelicious qodelicious commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

Running a script whose shebang interpreter doesn't exist gave an internal error that pointed at a Rust source location:

Error: nu::shell::io::not_found

  × Not found
  ╰─▶   × Could not spawn foreground child: No such file or directory (os error 2)

   ╭────
 1 │ crates/nu-command/src/system/run_external.rs:323:17
   · ─────────────────────────┬─────────────────────────
   ·                          ╰── Not found
   ╰────

By the time the child is spawned, which has 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 the ldd case in the issue. The help includes the resolved path, so it's clear which file was run:

Error: nu::shell::external_command

  × External command failed
   ╭─[entry #1:1:1]
 1 │ ./script.sh
   · ─────┬─────
   ·      ╰── `./script.sh` exists but could not be started
   ╰────
  help: `/path/to/script.sh` starts with `#!/nonexistent/interpreter`, but `/nonexistent/interpreter` was not found (No such file or directory (os error 2))

This hint is Unix-only and only used when the file still exists; on Windows, or when the file was removed after which found 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, ^ and run-external forms):

  • missing_shebang_interpreter_error
  • non_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)

  • Running a script whose shebang interpreter is missing now names the interpreter, and a program missing a file it needs (such as a shared library) says so, instead of showing an internal "Could not spawn foreground child" error with a Rust source location. Other errors from starting an external command point at the command and its path.

Additional notes

Fixes #15970

Tests + formatting:

  • cargo fmt --all -- --check
  • cargo clippy -p nu-config -p nu-cmd-lang -p nu-command -p nu-cli -p nu-explore --all-targets -- -D warnings -D clippy::unwrap_used
  • cargo test -p nu-command --test tests -- commands::run_external

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.

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity · 3 Medium severity · 3 Low severity

Open (6)

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.
@fdncred

fdncred commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Please reply to each review comment to ensure nothing is missed.

@fdncred fdncred left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review overview

🟡 Changes recommended

All six points from my last review are fixed. This is one small leftover from the new commit.

Findings: 0 High severity · 0 Medium severity · 1 Low severity

Open (1)

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low severity 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it back above command_not_found.

@fdncred
fdncred merged commit 877ed65 into nushell:main Oct 19, 2026
11 checks passed
@fdncred

fdncred commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.117.0 milestone Oct 19, 2026
@fdncred fdncred added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes labels Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusing error message when running script that couldn't find the shebang exe

2 participants