Improve handling of json output (#43138) #48658
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
(This is #48492, but cherry-picked against 2017.7)
Rather than look for [ or { at the beginning of a line, it looks for equality. Since the JSON output of
npm install
seems to have the first character on its own, this seems to work, at least for the npm version I looked at -- however, I'm open to better / other approaches that would be better. I think the previous approach was a bit too limited, since there could be other output in the future that matches^[
or^{
.Not sure if we could just ignore either stdout or stderr (I think some versions of node send the json output to stdout), or if there's another way this could be fixed. I am guessing the json output is reasonably consistent, but haven't tested older versions. [edit, checked, and currently, the message is going to stdout as well as the json output, so that won't work here]
What issues does this PR fix or reference?
Idempotency issue - first run will "fail" with an error, even when packages get installed, if the output has a string like:
[grpc] Success: "/usr/lib/node_modules/@google-cloud/monitoring/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-glibc/grpc_node.node" is installed via remote
, the first run will fail because the json parsing routine fails.More details in #43138; replaces #48492
Tests written?
Yes
Commits signed with GPG?
Yes