Thanks to visit codestin.com
Credit goes to github.com

Skip to content

shell.exec() ignores fatal option when not set globally #981

@chrisromano

Description

@chrisromano

Node version (or tell us if you're using electron or some other framework):

v10.17.0

ShellJS version (the most recent version/Github branch you see the bug on):

0.8.3

Operating system:

Ubuntu 18.04.3 LTS (via Windows 10 WSL)

Description of the bug:

When running shell.exec(), passing in {fatal:true} option is ignored.
Other options seem to work correctly, and setting config.fatal globally has desired behavior.

Example ShellJS command to reproduce the error:

# Executing an invalid command
> shelljs.exec('foobar')
/bin/sh: 1: foobar: not found
{ [String: '']
  stdout: '',
  stderr: '/bin/sh: 1: foobar: not found\n',
  code: 127,
  cat: [Function: bound ],
  exec: [Function: bound ],
  grep: [Function: bound ],
  head: [Function: bound ],
  sed: [Function: bound ],
  sort: [Function: bound ],
  tail: [Function: bound ],
  to: [Function: bound ],
  toEnd: [Function: bound ],
  uniq: [Function: bound ] }

# Same behavioir when passing in fatal:true
> shelljs.exec('foobar', {fatal:true})
/bin/sh: 1: foobar: not found
{ [String: '']
  stdout: '',
  stderr: '/bin/sh: 1: foobar: not found\n',
  code: 127,
  cat: [Function: bound ],
  exec: [Function: bound ],
  grep: [Function: bound ],
  head: [Function: bound ],
  sed: [Function: bound ],
  sort: [Function: bound ],
  tail: [Function: bound ],
  to: [Function: bound ],
  toEnd: [Function: bound ],
  uniq: [Function: bound ] }

# Setting global option has expected behavior
> shelljs.config.fatal = true
true
> shelljs.exec('foobar')
/bin/sh: 1: foobar: not found
Thrown:
Error: exec: /bin/sh: 1: foobar: not found

    at Object.error (/home/chris/sample/node_modules/shelljs/src/common.js:110:27)
    at execSync (/home/chris/sample/node_modules/shelljs/src/exec.js:102:12)
    at Object._exec (/home/chris/sample/node_modules/shelljs/src/exec.js:205:12)
    at Object.exec (/home/chris/sample/node_modules/shelljs/src/common.js:335:23)

# Setting silent: true appears to have desired effect.
> shelljs.exec('foobar', {silent:true})
Thrown:
Error: exec: /bin/sh: 1: foobar: not found

    at Object.error (/home/chris/sample/node_modules/shelljs/src/common.js:110:27)
    at execSync (/home/chris/sample/node_modules/shelljs/src/exec.js:102:12)
    at Object._exec (/home/chris/sample/node_modules/shelljs/src/exec.js:205:12)
    at Object.exec (/home/chris/sample/node_modules/shelljs/src/common.js:335:23)

Metadata

Metadata

Assignees

No one assigned

    Labels

    execIssues specific to the shell.exec() APIfeature

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions