Yarn: `yarn run` has changed behaviour, and generates a `yarn-error.log` file for exit code 1

Created on 6 Mar 2018  ·  16Comments  ·  Source: yarnpkg/yarn

Recently, yarn run has changed behaviour and has started outputting an error message and generating a yarn-error.log file when a non-zero exit code occurs. Previously it would just exit with code 1. This was useful for running tests or linters, where an exit code of 1 is as expected outcome, and helps to automatically stop a build system when tests/linting fails.

Do you want to request a feature or report a bug?
Report a bug.

What is the current behavior?
Running scripts from package.json that return exit code 1 will output an error message and generate a yarn-error.log file, e.g.:

error An unexpected error occurred: "Command failed.
Exit code: 1
Command: sh
Arguments: -c eslint --ext js,jsx --max-warnings 0 .
Directory: /Users/tim/Documents/foo
Output:
".
info If you think this is a bug, please open a bug report with the information provided in "/Users/tim/Documents/foo/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If the current behavior is a bug, please provide the steps to reproduce.
Run a script that exits with code 1, e.g. ESLint:

{
  "scripts": {
    "lint": "eslint --ext js,jsx --max-warnings 0 ."
  }
}

What is the expected behavior?
Previously, yarn run would just exit with code 1.

  1. I can't find the release information or documentation about this change in behaviour. Does anyone know what version introduced this change?
  2. Is there a way to flag that exit code 1 for a script is an expected outcome?

Please mention your node.js, yarn and operating system version.
node 9.6.1, yarn 1.5.1, macOS 10.13.3

cat-bug help wanted high-priority triaged

Most helpful comment

This isn't the intended behavior, if I'm not mistaken.

There is special handling in place for errors originating in child processes, but due to a bug outlined in #5451 and fixed in #5497 (and I'm assuming released with 1.6.0; can't test since it hasn't been packaged for Arch yet), those handlers weren't able to catch the exceptions that were meant for them, so Yarn was thinking that those are unexpected internal errors, hence the verbosity and yarn-error.log.

All 16 comments

See also #5451

I'm getting this same issue.

node 9.8.0, yarn 1.5.1, macOS 10.13.3

the same problem... node 8.10.0 yarn 1.5.1 Ubuntu 16.04

Same issue.

  • Node v8.9.1
  • Yarn v1.5.1
  • Windows v10.0.16299.309

Same:
Yarn version: 1.5.1
Node version: 9.2.1
Platform: Darwin x64

error An unexpected error occurred: "Command failed.
Exit code: 1
Command: sh
Arguments: -c cucumber-js

I've also noticed that if all my tests pass, the error goes away.

The same problem. Win 10, Node v.9.7.1, yarn 1.5.1 😢

:+1:

I've resorted to adding ; true to the end of scripts as a workaround. 😕

(from #5661) I suspect this functionality was added to prevent a flood of bogus bug reports for things that were not yarn bugs. I think that makes sense, and I support the yarn authors in trying to preserve their own sanity :)

I suggest some kind of opt-out functionality in .yarnrc that would truncate the nine-line error message to the old single line and avoid writing a yarn-error.log in the case where a script returns a nonzero exit status.

This isn't the intended behavior, if I'm not mistaken.

There is special handling in place for errors originating in child processes, but due to a bug outlined in #5451 and fixed in #5497 (and I'm assuming released with 1.6.0; can't test since it hasn't been packaged for Arch yet), those handlers weren't able to catch the exceptions that were meant for them, so Yarn was thinking that those are unexpected internal errors, hence the verbosity and yarn-error.log.

This looks fixed by the release of 1.6.0

Upgraded and ran yarn run v1.6.0. Still getting an error

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Should I open a new issue?

@mjstelly That's the _exact_ same output generated by yarn v1.3.2 for an exit code 1. Also, obviously "if all my tests pass, the error goes away." is a result of an exit code 0. Please don't create extra noise, this issue it related only to yarn-error.log file generation and deviations from previous behaviour.

The same trouble,
everytime after "yarn start" failed, then I "yarn"(although it throw error), "yarn start"again, it works!
每次windows上yarn start失败后,我直接再yarn一下(它可能会报错不过没有关系请无视),再“yarn
start”就能成功开启server服务了,我也不知道为什么。

@SageSanyue that sounds like a different bug. This bug is not about the failures, but about the excessive logging when those errors occur.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DannyBrown picture DannyBrown  ·  89Comments

jshthornton picture jshthornton  ·  72Comments

jiripospisil picture jiripospisil  ·  128Comments

jmorrell picture jmorrell  ·  93Comments

fahrradflucht picture fahrradflucht  ·  120Comments