Skip to main content

resolve_program

Function resolve_program 

Source
pub fn resolve_program(program: PathBuf) -> PathBuf
Expand description

Resolve a bare program name (bob, claude) to its absolute path on the augmented PATH, so the spawn and the node pairing agree on one location.

Without this, a bare name splits the brain: the OS resolves the program against the parent process’s PATH, while the child’s #!/usr/bin/env node shebang resolves node against the PATH we set — and [prepend_program_dir] can’t pair the program with its sibling node because a bare name has no parent dir. Concretely: an nvm-installed bob found under v24/bin could re-exec on a v20 node that happened to lead the inherited PATH, and die on a v24-only flag (“exited with code 9”). Resolving to the absolute path first means the program’s own directory — holding the exact node it was installed with — is prepended and wins.

A program given with an explicit path is returned untouched; a bare name that can’t be found is also returned untouched, so the spawn still fails with the clear “No such file” error rather than a synthetic one here.