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

[Bug?]: I used this.cli.run([this.commandName, ...this.args], this.context);, but the console does not output correctly #3354

Closed
1 task
rxliuli opened this issue Aug 27, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@rxliuli
Copy link

rxliuli commented Aug 27, 2021

Self-service

  • I'd be willing to implement a fix

Describe the bug

When there is an error, it will not return 1

image

To reproduce

  1. Let an error code exist in a submodule
  2. Run yarn changed foreach run build

https://github.com/rxliuli/liuli-tools/blob/586446ad046b3d5a4b3ad79c53777869131f5d4d/libs/yarn-plugin-changed/src/commands/ChangedForeachCommand.ts#L32

Environment

System:
OS: Windows 10 10.0.19043
CPU: (16) x64 Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz
Binaries:
Node: 14.17.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.11 - C:\Program Files\nodejs\yarn.CMD
npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD

Additional context

No response

@rxliuli rxliuli added the bug Something isn't working label Aug 27, 2021
@merceyz
Copy link
Member

merceyz commented Aug 27, 2021

Sounds like #3334, do you get exit code 0 when you run it manually?

@rxliuli
Copy link
Author

rxliuli commented Aug 27, 2021

Does manual operation mean running on the wrong module? Yes, it will display a red error and terminate

@merceyz
Copy link
Member

merceyz commented Aug 30, 2021

No, if you run the command in your terminal instead of using this.cli.run do you then see an exit code? Do you see an exit code other than 0 when you run the failing command outside of workspaces foreach?

@rxliuli
Copy link
Author

rxliuli commented Aug 30, 2021

No, if you run the command in your terminal instead of using this.cli.run do you then see an exit code? Do you see an exit code other than 0 when you run the failing command outside of workspaces foreach?

yarn workspaces foreach

$ yarn workspaces foreach --include @liuli-util/i18next-util --parallel --topological-dev run setup
➤ YN0000: (node:21180) UnhandledPromiseRejectionWarning: Error: C:/Users/rxliuli/Code/Pkg/liuli-tools/libs/i18next-util/src/index.ts(2,1): semantic error TS2304: Cannot find name 'sd'.
➤ YN0000:     at error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:151:30)
➤ YN0000:     at throwPluginError (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:19344:12)
➤ YN0000:     at Object.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:20013:20)
➤ YN0000:     at Object.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:19520:38)
➤ YN0000:     at RollupContext.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:17241:30)
➤ YN0000:     at C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:25064:23
➤ YN0000:     at arrayEach (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:549:11)
➤ YN0000:     at Function.forEach (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:9401:14)
➤ YN0000:     at printDiagnostics (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:25037:12)
➤ YN0000:     at Object.transform (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:30131:17)
➤ YN0000: (Use `node --trace-warnings ...` to show where the warning was created)
➤ YN0000: (node:21180) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
➤ YN0000: (node:21180) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
➤ YN0000: Done in 3s 874ms

this.cli.run

$ yarn changed foreach --include @liuli-util/i18next-util -p --topological-dev run setup
  计算得到变更的模块:
@liuli-util/i18next-util
execute before:  workspaces foreach --include @liuli-util/i18next-util --parallel --topological-dev run setup
➤ YN0000: (node:37240) UnhandledPromiseRejectionWarning: Error: C:/Users/rxliuli/Code/Pkg/liuli-tools/libs/i18next-util/src/index.ts(2,1): semantic error TS2304: Cannot find name 'sd'.
➤ YN0000:     at error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:151:30)
➤ YN0000:     at throwPluginError (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:19344:12)
➤ YN0000:     at Object.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:20013:20)
➤ YN0000:     at Object.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:19520:38)
➤ YN0000:     at RollupContext.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:17241:30)
➤ YN0000:     at C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:25064:23
➤ YN0000:     at arrayEach (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:549:11)
➤ YN0000:     at Function.forEach (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:9401:14)
➤ YN0000:     at printDiagnostics (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:25037:12)
➤ YN0000:     at Object.transform (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:30131:17)
➤ YN0000: (Use `node --trace-warnings ...` to show where the warning was created)
➤ YN0000: (node:37240) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
➤ YN0000: (node:37240) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
➤ YN0000: Done in 3s 773ms
execute after:  0

@rxliuli
Copy link
Author

rxliuli commented Aug 30, 2021

No, if you run the command in your terminal instead of using this.cli.run do you then see an exit code? Do you see an exit code other than 0 when you run the failing command outside of workspaces foreach?

yarn workspaces foreach

$ yarn workspaces foreach --include @liuli-util/i18next-util --parallel --topological-dev run setup
➤ YN0000: (node:21180) UnhandledPromiseRejectionWarning: Error: C:/Users/rxliuli/Code/Pkg/liuli-tools/libs/i18next-util/src/index.ts(2,1): semantic error TS2304: Cannot find name 'sd'.
➤ YN0000:     at error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:151:30)
➤ YN0000:     at throwPluginError (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:19344:12)
➤ YN0000:     at Object.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:20013:20)
➤ YN0000:     at Object.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:19520:38)
➤ YN0000:     at RollupContext.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:17241:30)
➤ YN0000:     at C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:25064:23
➤ YN0000:     at arrayEach (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:549:11)
➤ YN0000:     at Function.forEach (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:9401:14)
➤ YN0000:     at printDiagnostics (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:25037:12)
➤ YN0000:     at Object.transform (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:30131:17)
➤ YN0000: (Use `node --trace-warnings ...` to show where the warning was created)
➤ YN0000: (node:21180) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
➤ YN0000: (node:21180) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
➤ YN0000: Done in 3s 874ms

Console log executed by this.cli.run

$ yarn changed foreach --include @liuli-util/i18next-util -p --topological-dev run setup
  计算得到变更的模块:
@liuli-util/i18next-util
execute before:  workspaces foreach --include @liuli-util/i18next-util --parallel --topological-dev run setup
➤ YN0000: (node:37240) UnhandledPromiseRejectionWarning: Error: C:/Users/rxliuli/Code/Pkg/liuli-tools/libs/i18next-util/src/index.ts(2,1): semantic error TS2304: Cannot find name 'sd'.
➤ YN0000:     at error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:151:30)
➤ YN0000:     at throwPluginError (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:19344:12)
➤ YN0000:     at Object.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:20013:20)
➤ YN0000:     at Object.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup\dist\shared\rollup.js:19520:38)
➤ YN0000:     at RollupContext.error (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:17241:30)
➤ YN0000:     at C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:25064:23
➤ YN0000:     at arrayEach (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:549:11)
➤ YN0000:     at Function.forEach (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:9401:14)
➤ YN0000:     at printDiagnostics (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:25037:12)
➤ YN0000:     at Object.transform (C:\Users\rxliuli\Code\Pkg\liuli-tools\node_modules\rollup-plugin-typescript2\dist\rollup-plugin-typescript2.cjs.js:30131:17)
➤ YN0000: (Use `node --trace-warnings ...` to show where the warning was created)
➤ YN0000: (node:37240) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
➤ YN0000: (node:37240) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
➤ YN0000: Done in 3s 773ms
execute after:  0

Looks like a problem with yarn workspaces foreach

@rxliuli
Copy link
Author

rxliuli commented Aug 30, 2021

I added a reproducible example

Steps to reproduce

  1. git clone https://github.com/rxliuli/liuli-tools/tree/bug_yarn2_cli_run && cd liuli-tools
  2. yarn
  3. cd apps/liuli-cli && yarn build
  4. cd ../.. && yarn setup
  5. Got this error

In order to see the actual executed command, I printed it out and can execute it

yarn workspaces foreach --include @liuli-util/i18next-util --parallel --topological-dev run setup

@merceyz
Copy link
Member

merceyz commented Aug 30, 2021

As I mentioned on Discord, your screenshot shows a warning not an error. When I run it on Node 16 I do get an error and this.cli.run returns 1, on Node 14 it's a warning and it returns 0

See https://nodejs.org/dist/latest/docs/api/deprecations.html#deprecations_dep0018_unhandled_promise_rejections
Ref nodejs/node#33021

@merceyz merceyz closed this as completed Aug 30, 2021
@rxliuli
Copy link
Author

rxliuli commented Aug 30, 2021

As I mentioned on Discord, your screenshot shows a warning not an error. When I run it on Node 16 I do get an error and this.cli.run returns 1, on Node 14 it's a warning and it returns 0

See https://nodejs.org/dist/latest/docs/api/deprecations.html#deprecations_dep0018_unhandled_promise_rejections
Ref nodejs/node#33021

Is there a way to make it correct on nodejs 14? After all, now 14 is still a long-term support version

@merceyz
Copy link
Member

merceyz commented Oct 2, 2021

Yes, read the docs I linked to. This isn't a Yarn issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants