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

feat: output json formatted errors on stdout #5716

Merged
merged 1 commit into from
Oct 19, 2022
Merged

Conversation

lukekarrys
Copy link
Contributor

This also adds a new output method outputBuffer() which will buffer
all output until it is flushed in the exit handler. This allows the exit
handler to catch any errors and append them to the output when in json
mode. This was necessary to not introduce a regression in the case of
#2150.

BREAKING CHANGE: npm now outputs some json errors on stdout.
Previously npm would output all json formatted errors on stderr,
making it difficult to parse as the stderr stream usually has logs
already written to it. In the future, npm will differentiate between
errors and crashes. Errors, such as E404 and ERESOLVE, will be
handled and will continue to be output on stdout. In the case of a
crash, npm will log the error as usual but will not attempt to display
it as json, even in --json mode. Moving a case from the category of an
error to a crash will not be considered a breaking change. For more
information see npm/rfcs#482.

Closes #2740
Closes npm/statusboard#589

This also adds a new output method `outputBuffer()` which will buffer
all output until it is flushed in the exit handler. This allows the exit
handler to catch any errors and append them to the output when in json
mode. This was necessary to not introduce a regression in the case of
#2150.

BREAKING CHANGE: `npm` now outputs some json errors on stdout.
Previously `npm` would output all json formatted errors on stderr,
making it difficult to parse as the stderr stream usually has logs
already written to it. In the future, `npm` will differentiate between
errors and crashes. Errors, such as `E404` and `ERESOLVE`, will be
handled and will continue to be output on stdout. In the case of a
crash, `npm` will log the error as usual but will not attempt to display
it as json, even in `--json` mode. Moving a case from the category of an
error to a crash will not be considered a breaking change. For more
information see npm/rfcs#482.

Closes #2740
Closes npm/statusboard#589
@@ -177,7 +177,7 @@ class LS extends ArboristWorkspaceCmd {
const [rootError] = tree.errors.filter(e =>
e.code === 'EJSONPARSE' && e.path === resolve(path, 'package.json'))

this.npm.output(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we only calling this in one command for now?

Copy link
Member

@wraithgar wraithgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved w/ one question that I'm pretty sure was an intentional choice given the linked issue we are trying to prevent a regression on, but I thought I'd still ask.

@lukekarrys lukekarrys merged commit 46d038f into latest Oct 19, 2022
@lukekarrys lukekarrys deleted the lk/json-error-stdout branch October 19, 2022 17:04
lukekarrys added a commit that referenced this pull request Oct 19, 2022
This also adds a new output method `outputBuffer()` which will buffer
all output until it is flushed in the exit handler. This allows the exit
handler to catch any errors and append them to the output when in json
mode. This was necessary to not introduce a regression in the case of
#2150.

BREAKING CHANGE: `npm` now outputs some json errors on stdout.
Previously `npm` would output all json formatted errors on stderr,
making it difficult to parse as the stderr stream usually has logs
already written to it. In the future, `npm` will differentiate between
errors and crashes. Errors, such as `E404` and `ERESOLVE`, will be
handled and will continue to be output on stdout. In the case of a
crash, `npm` will log the error as usual but will not attempt to display
it as json, even in `--json` mode. Moving a case from the category of an
error to a crash will not be considered a breaking change. For more
information see npm/rfcs#482.

Closes #2740
Closes npm/statusboard#589
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.

BREAKING CHANGE(output): make --json parseable again [BUG] NPM 7.x broke the "--json" CLI parameter
2 participants