Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nx exec prints the help docs multiple times when executed command returns non-zero exit code #14202

Closed
jeffhertzler opened this issue Jan 6, 2023 · 1 comment · Fixed by #14237
Assignees
Labels

Comments

@jeffhertzler
Copy link

jeffhertzler commented Jan 6, 2023

Current Behavior

nx exec prints the help docs multiple times when executed command returns non-zero exit code

Expected Behavior

I would expect the help to not be generated either time. I would also expect the exit code to propagate down from the original npm script. Basically I would expect it to work the same as if I was not using nx exec and was instead calling nx directly:

❯ npx nx fail

> nx run gg-api-gateway:fail

> fail
> exit 1

 ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target undefined for project gg-api-gateway (351ms)

    ✖    1/1 failed
    ✔    0/1 succeeded [0 read from cache]

The primary use case I have for this is trying to run tests thru nx exec. Test runners typically return a non-zero exit code when a test fails.

Github Repo

No response

Steps to Reproduce

  1. add script that can fail to package.json that uses nx exec:
{
  "scripts": {
    "fail": "nx exec -- exit 1"
  }
}
  1. run script in terminal:
❯ npm run fail

> fail
> nx exec -- exit 1


> nx run my-node-app:fail

> fail
> nx exec -- exit 1
nx exec
Executes any command as if it was a target on the project
Options:
      --version            Show version number  [boolean]
  -c, --configuration      This is the configuration to use when performing tasks on projects  [string]
  -t, --targets, --target  Tasks to run for affected projects  [string]
      --output-style       Defines how Nx emits outputs tasks logs  [string] [choices: "dynamic", "static", "stream", "stream-without-prefixes", "compact"]
      --exclude            Exclude certain projects from being processed  [string] [default: ""]
      --parallel           Max number of parallel processes [default is 3]  [string]
      --runner             This is the name of the tasks runner configured in nx.json  [string]
      --verbose            Prints additional information about the commands (e.g., stack traces)  [boolean] [default: false]
      --nx-bail            Stop command execution after the first failed task  [boolean] [default: false]
      --nx-ignore-cycles   Ignore cycles in the task graph  [boolean] [default: false]
      --skip-nx-cache      Rerun the tasks even when the results are available in the cache  [boolean] [default: false]
      --project            Target project  [string]
Error: Command failed: "exit" "1"
    at checkExecSyncError (node:child_process:828:11)
    at execSync (node:child_process:899:15)
    at Object.<anonymous> (/.../my-node-app/node_modules/nx/src/command-line/exec.js:25:42)
    at Generator.next (<anonymous>)
    at /.../my-node-app/node_modules/tslib/tslib.js:118:75
    at new Promise (<anonymous>)
    at Object.__awaiter (/.../my-node-app/node_modules/tslib/tslib.js:114:16)
    at Object.nxExecCommand (.../my-node-app/node_modules/nx/src/command-line/exec.js:18:20)
    at /.../my-node-app/node_modules/nx/src/command-line/nx-commands.js:272:71 {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 1678350,
  stdout: null,
  stderr: null
}

 ————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 >  NX   Ran target undefined for project my-node-app (529ms)

    ✖    1/1 failed
    ✔    0/1 succeeded [0 read from cache]

nx exec

Executes any command as if it was a target on the project

Options:
      --version            Show version number                                                                       [boolean]
  -c, --configuration      This is the configuration to use when performing tasks on projects                         [string]
  -t, --targets, --target  Tasks to run for affected projects                                                         [string]
      --output-style       Defines how Nx emits outputs tasks logs
                                       [string] [choices: "dynamic", "static", "stream", "stream-without-prefixes", "compact"]
      --exclude            Exclude certain projects from being processed                                [string] [default: ""]
      --parallel           Max number of parallel processes [default is 3]                                            [string]
      --runner             This is the name of the tasks runner configured in nx.json                                 [string]
      --verbose            Prints additional information about the commands (e.g., stack traces)    [boolean] [default: false]
      --nx-bail            Stop command execution after the first failed task                       [boolean] [default: false]
      --nx-ignore-cycles   Ignore cycles in the task graph                                          [boolean] [default: false]
      --skip-nx-cache      Rerun the tasks even when the results are available in the cache         [boolean] [default: false]
      --project            Target project                                                                             [string]

Error: Command failed: npx nx run my-node-app:\"fail\"
    at checkExecSyncError (node:child_process:828:11)
    at execSync (node:child_process:899:15)
    at /.../my-node-app/node_modules/nx/src/command-line/exec.js:48:45
    at Generator.next (<anonymous>)
    at fulfilled (/.../my-node-app/node_modules/tslib/tslib.js:115:62)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 1678289,
  stdout: null,
  stderr: null
}

Nx Report

>  NX   Report complete - copy this into the issue template

   Node : 16.15.1
   OS   : linux x64
   npm  : 8.11.0

   nx : 15.4.4
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : Not Found
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : Not Found
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : Not Found
   @nrwl/js : Not Found
   @nrwl/linter : Not Found
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : Not Found
   @nrwl/workspace : Not Found
   @nrwl/vite : Not Found
   typescript : 4.9.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Failure Logs

No response

Additional Information

No response

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants