@@ -228,11 +228,15 @@ export const readTailscaleStatus = Effect.gen(function* () {
228228 argumentCount : args . length ,
229229 } ;
230230 return yield * Effect . gen ( function * ( ) {
231- const child = yield * spawner
232- . spawn ( ChildProcess . make ( executable , args ) )
233- . pipe (
234- Effect . mapError ( ( cause ) => new TailscaleCommandSpawnError ( { ...commandContext , cause } ) ) ,
235- ) ;
231+ const child = yield * spawner . spawn ( ChildProcess . make ( executable , args ) ) . pipe (
232+ Effect . mapError ( ( cause ) => new TailscaleCommandSpawnError ( { ...commandContext , cause } ) ) ,
233+ // Spawning can also fail as a defect rather than a typed error - a
234+ // non-directory entry on PATH makes node throw ENOTDIR synchronously.
235+ // `mapError` never sees that, so it would escape as an uncaught error.
236+ Effect . catchDefect ( ( cause ) =>
237+ Effect . fail ( new TailscaleCommandSpawnError ( { ...commandContext , cause } ) ) ,
238+ ) ,
239+ ) ;
236240 const [ stdout , stderr , exitCode ] = yield * Effect . all (
237241 [
238242 collectStdout ( child . stdout ) ,
@@ -299,11 +303,12 @@ const runTailscaleCommand = (
299303 } ;
300304 const timeout = Duration . fromInputUnsafe ( timeoutInput ) ;
301305 return yield * Effect . gen ( function * ( ) {
302- const child = yield * spawner
303- . spawn ( ChildProcess . make ( executable , args ) )
304- . pipe (
305- Effect . mapError ( ( cause ) => new TailscaleCommandSpawnError ( { ...commandContext , cause } ) ) ,
306- ) ;
306+ const child = yield * spawner . spawn ( ChildProcess . make ( executable , args ) ) . pipe (
307+ Effect . mapError ( ( cause ) => new TailscaleCommandSpawnError ( { ...commandContext , cause } ) ) ,
308+ Effect . catchDefect ( ( cause ) =>
309+ Effect . fail ( new TailscaleCommandSpawnError ( { ...commandContext , cause } ) ) ,
310+ ) ,
311+ ) ;
307312 const [ stderr , exitCode ] = yield * Effect . all (
308313 [ collectStderr ( child . stderr ) , child . exitCode . pipe ( Effect . map ( Number ) ) ] ,
309314 { concurrency : "unbounded" } ,
0 commit comments