npm / node-which

Like which(1) unix command. Find the first instance of an executable in the PATH.
ISC License
326 stars 48 forks source link

[FEATURE] nothrow option for async which #80

Closed Benjin closed 1 year ago

Benjin commented 3 years ago

Somewhat self-explanatory, but this option exists for the which.sync and not which. It'd be nice to have it for both, and there doesn't seem to be anything inherently incompatible with the async implementation, just slightly messy.

rlueder commented 1 year ago

It seems that nothrow: true is only working working for which.sync and still throws an error for the async version. To reproduce using which v.3.0.0

  try {
    which.sync(command, { nothrow: true })
  } catch (error) {
    console.error(`${error.message}`);
  }

has no console output as expected (ie. it's null) while

  try {
    which(command, { nothrow: true })
  } catch (error) {
    console.error(`${error.message}`);
  }

still throws:

/node_modules/zx/node_modules/which/which.js:10
  Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' })
                ^

Error: not found: xcodes
    at getNotFoundError (/node_modules/zx/node_modules/which/which.js:10:17)
    at /node_modules/zx/node_modules/which/which.js:57:18
    at new Promise (<anonymous>)
    at step (/node_modules/zx/node_modules/which/which.js:54:21)
    at /node_modules/zx/node_modules/which/which.js:71:22
    at new Promise (<anonymous>)
    at subStep (/node_modules/zx/node_modules/which/which.js:69:33)
    at /node_modules/zx/node_modules/which/which.js:80:22
    at /node_modules/isexe/index.js:42:5
    at /node_modules/isexe/mode.js:8:5 {
  code: 'ENOENT'
}
lukekarrys commented 1 year ago

@rlueder it looks like you might have multiple versions of which in your tree because the example you pasted is referencing /node_modules/zx/node_modules/which/which.js:10. that file no longer exists and has been replaced by lib/index.js.

can you trying reinstalling which@3 and trying your example again?