-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Conversation
0db7dcc
to
cf39551
Compare
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
cf39551
to
6c870b4
Compare
@@ -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( |
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
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 bufferall 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 betweenerrors and crashes. Errors, such as
E404
andERESOLVE
, will behandled 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 displayit as json, even in
--json
mode. Moving a case from the category of anerror to a crash will not be considered a breaking change. For more
information see npm/rfcs#482.
Closes #2740
Closes npm/statusboard#589