Skip to content

feat: --fail-on-warnings / failOnWarnings#7068

Open
NormalGaussian wants to merge 1 commit intoyarnpkg:masterfrom
NormalGaussian:feat/fail-on-warnings
Open

feat: --fail-on-warnings / failOnWarnings#7068
NormalGaussian wants to merge 1 commit intoyarnpkg:masterfrom
NormalGaussian:feat/fail-on-warnings

Conversation

@NormalGaussian
Copy link
Copy Markdown

yarn commands can be made to exit with a non-zero status code due to the presence of warnings logged during execution.

What's the problem this PR addresses?

Its a partial resolution to #7066

CI / testing workflows want to proactively avoid bugs and issues in the repo's they manage whilst being clear and easy to maintain themselves. Yarn emitting warnings is a clear indication of potential bugs and issues in the repo, but it is not clear and easy to detect such warnings. A simple grep is prone to false positives (e.g. a package name) and more complex solutions are difficult to understand, adequately maintain, and demonstrate as being free of bugs e.g.

yarn install --json | tee >(jq -c 'select( .type == "warning")' > warnings.jsonl) | jq -r '.indent + .data'
test "$(wc -l < warnings.jsonl)" -gt 0 && echo "Unfiltered warnings found in 'yarn install'" && exit 1

yarn install --fail-on-warnings is a lot simpler.

How did you fix it?

The CLI option --fail-on-warnings was added as an option to BaseCommand and its presence propagated to StreamReport.start({...}) as failOnWarnings. When StreamReport determines the exitCode it now takes into consideration the failOnWarnings setting and the presence of warnings.

Of note: the change was added to BaseCommand, which seemed the most appropriate as this is a generic behaviour, but it was added as a hidden option as it seemed to confusingly pollute yarn -h for most users, for what is generally a CI option. This has made it unclear as to how best to document.

Checklist

  • I have read the Contributing Guide.
  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

The option --fail-on-warnings / failOnWarnings causes executions which
emit warnings to exit with a non-zero exit code (1).
@NormalGaussian
Copy link
Copy Markdown
Author

The failing checks appear to be the Error: EBADF: bad file descriptor, fstat that has been present since Node 25.7.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant