Deno: Deno.run() cannot get status when we run a invalid command

Created on 31 May 2019  路  7Comments  路  Source: denoland/deno

(async ()=> {
    const process= Deno.run( { cmd: [ 'invalid-command', ], }, );

    console.log( await process.status(), );
})();

It should log { code: 127, success: false }. But in fact, an error thrown.

bug

Most helpful comment

I have been taking a look at this issue, and this error at the surface is due to a method call to map from the cmd field of first parameter of the Deno.run.

cmd does not have a default value and crashes if undefined or not an array. There is also this assertion, assert(request.cmd.length > 0). Perhaps more friendly logging would be helpful here.

When args is replaced with cmd in the code above, this is the new error:

error: Uncaught NotFound: No such file or directory (os error 2)
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
    at Object.run ($deno$/ops/process.ts:41:10)
    at Object.run ($deno$/process.ts:118:15)
    at file:///Users/barronwei/Desktop/test.js:2:22
    at file:///Users/barronwei/Desktop/test.js:5:3

If no one else is working on this, I would love to continue working on this issue!

All 7 comments

I have been taking a look at this issue, and this error at the surface is due to a method call to map from the cmd field of first parameter of the Deno.run.

cmd does not have a default value and crashes if undefined or not an array. There is also this assertion, assert(request.cmd.length > 0). Perhaps more friendly logging would be helpful here.

When args is replaced with cmd in the code above, this is the new error:

error: Uncaught NotFound: No such file or directory (os error 2)
    at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
    at Object.sendSync ($deno$/ops/dispatch_json.ts:72:10)
    at Object.run ($deno$/ops/process.ts:41:10)
    at Object.run ($deno$/process.ts:118:15)
    at file:///Users/barronwei/Desktop/test.js:2:22
    at file:///Users/barronwei/Desktop/test.js:5:3

If no one else is working on this, I would love to continue working on this issue!

@barronwei Thanks for the analysis and a patch would be very welcome!

Great issue @barronwei, hope you can fix it!

cmd does not have a default value and crashes if undefined or not an array.

This issue is open before parameter name args breaking change to cmd. And I've forgot to update it. That's two different issues:

  • a non-exist command should give exit code 127.
  • when user forget to pass cmd, should give a better error.

@Fenzland Appreciate the distinction. I will keep this in mind!

@Fenzland I believe exit code 127 is Bash specific. If the command dos not exist, Tokio does not successfully spawn a new process through Command::spawn, and results in an error. Anything to keep in mind when handling this, @ry?

~/src/deno> cat x.js
(async ()=> {
    const process= Deno.run( { cmd: [ 'invalid-command', ], }, );

    console.log( await process.status(), );
})();
~/src/deno> deno run --allow-run x.js
error: Uncaught NotFound: No such file or directory (os error 2)
    at Object.jsonOpSync (core.js:247:13)
    at opRun (deno:cli/rt/40_process.js:19:17)
    at Object.run (deno:cli/rt/40_process.js:103:17)
    at file:///Users/rld/src/deno/x.js:2:22
    at file:///Users/rld/src/deno/x.js:5:3

This seems correct

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zugende picture zugende  路  3Comments

ry picture ry  路  3Comments

sh7dm picture sh7dm  路  3Comments

CruxCv picture CruxCv  路  3Comments

ry picture ry  路  3Comments