@@ -99,8 +99,8 @@ const cwdFailure = (cwd: string, cause: NodeJS.ErrnoException) =>
9999
100100/**
101101 * Fails as a native spawn does when the command is missing or not executable: callers read
102- * that error to tell a CLI that is not installed from one that failed. execvp reports EACCES
103- * when a candidate exists but cannot be run, and ENOENT otherwise.
102+ * that error to tell a CLI that is not installed from one that failed. When PATH is exhausted,
103+ * execvp reports EACCES if any candidate was denied, or the last lookup error otherwise.
104104 */
105105const findExecutable = Effect . fnUntraced ( function * (
106106 command : ChildProcess . StandardCommand ,
@@ -114,18 +114,25 @@ const findExecutable = Effect.fnUntraced(function* (
114114 : ( childPath ( command . options ) ?? DEFAULT_PATH )
115115 . split ( ":" )
116116 . map ( ( entry ) => `${ fromCwd ( entry || "." ) } /${ command . command } ` ) ;
117- let denied = false ;
117+ let failure : "ENOENT" | "EACCES" | "ENOTDIR" = "ENOENT" ;
118118 for ( const candidate of candidates ) {
119119 const error = yield * check (
120120 candidate . slice ( 0 , candidate . lastIndexOf ( "/" ) ) || "/" ,
121121 candidate ,
122122 NodeFS . constants . X_OK ,
123123 ) ;
124+ const code = error ?. code ;
124125 // Any other errno is left for `env` to report through its exit code.
125- if ( error === undefined || ( error . code !== "ENOENT " && error . code !== "EACCES" ) ) return ;
126- denied ||= error . code === "EACCES" ;
126+ if ( code !== "ENOENT" && code !== "EACCES " && code !== "ENOTDIR" ) return ;
127+ if ( failure !== "EACCES" ) failure = code ;
127128 }
128- return yield * spawnFailure ( command , denied ? "EACCES" : "ENOENT" ) ;
129+ if ( failure === "ENOTDIR" ) {
130+ // Node throws synchronously here, and callers recognize ENOTDIR on the defect itself.
131+ return yield * Effect . die (
132+ Object . assign ( new Error ( "spawn ENOTDIR" ) , { errno : - 20 , code : "ENOTDIR" , syscall : "spawn" } ) ,
133+ ) ;
134+ }
135+ return yield * spawnFailure ( command , failure ) ;
129136} ) ;
130137
131138const make = Effect . gen ( function * ( ) {
@@ -138,7 +145,14 @@ const make = Effect.gen(function* () {
138145 const prepareStandard = Effect . fnUntraced ( function * ( input : ChildProcess . StandardCommand ) {
139146 const { cwd : givenCwd , shell, ...options } = input . options ;
140147 // Effect rejects a shell command with arguments, and a NUL, itself.
141- if ( ( shell && input . args . length > 0 ) || input . command . includes ( "\0" ) ) return input ;
148+ if (
149+ ( shell && input . args . length > 0 ) ||
150+ [ input . command , ...input . args ] . some ( ( arg ) =>
151+ ( Redacted . isRedacted ( arg ) ? Redacted . value ( arg ) : arg ) . includes ( "\0" ) ,
152+ )
153+ ) {
154+ return input ;
155+ }
142156 // Node's shell mode on Unix, spelled out so the trampoline can run it.
143157 const command = shell
144158 ? ChildProcess . make ( typeof shell === "string" ? shell : "/bin/sh" , [ "-c" , input . command ] )
0 commit comments