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

fix(#301): Handle JSONStream.parse() errors more gracefully #306

Merged
merged 1 commit into from
Jan 23, 2023

Conversation

quinnturner
Copy link
Member

No description provided.

Copy link
Member Author

@quinnturner quinnturner left a comment

Choose a reason for hiding this comment

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

I am not a master of Node.js streaming logic. If you have other ideas, please let me know!

.pipe(JSONStream.parse())
.pipe(
transform.on("error", (error) => {
throw error;
Copy link
Member Author

Choose a reason for hiding this comment

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

This wasn't strictly necessary, but it did convert an error location from within node:stream to this userland function.

proc.on("error", (error) => reject(error));
proc.on("close", () => {
if (errorMessage) {
return reject(new Error(errorMessage));
Copy link
Member Author

@quinnturner quinnturner Jan 13, 2023

Choose a reason for hiding this comment

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

Here's the error:

➜  node ../../dist/bin.js
audit-ci version: 6.5.0
Yarn Berry audit report results:
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: Internal Error: audit-ci-yarn-workspace@workspace:.: This package doesn't seem to be present in your lockfile; run "yarn install" to update the lockfile
    at Stream.<anonymous> (/Users/quinn/Dev/quinnturner/audit-ci/dist/common.js:132:15)
    at Stream.emit (node:events:525:35)
    at parser.onError (/Users/quinn/Dev/quinnturner/audit-ci/node_modules/JSONStream/index.js:142:12)
    at proto.charError (/Users/quinn/Dev/quinnturner/audit-ci/node_modules/jsonparse/jsonparse.js:90:8)
    at proto.write (/Users/quinn/Dev/quinnturner/audit-ci/node_modules/jsonparse/jsonparse.js:154:23)
    at Stream.<anonymous> (/Users/quinn/Dev/quinnturner/audit-ci/node_modules/JSONStream/index.js:23:12)
    at stream.write (/Users/quinn/Dev/quinnturner/audit-ci/node_modules/through/index.js:26:11)
    at Stream.ondata (node:internal/streams/legacy:20:31)
    at Stream.emit (node:events:513:28)
    at Stream.write (/Users/quinn/Dev/quinnturner/audit-ci/node_modules/event-stream/index.js:210:12)
Emitted 'error' event on ReadlineTransform instance at:
    at ReadlineTransform.onerror (node:internal/streams/readable:785:14)
    at ReadlineTransform.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

Node.js v19.3.0

I wouldn't say this is the cleanest error of all time, but it is much better than a JSONStream.parse() error!

Signed-off-by: Quinn Turner <quinnturnertech@gmail.com>
@quinnturner quinnturner merged commit 9f835b7 into IBM:main Jan 23, 2023
@quinnturner quinnturner deleted the error-handling branch January 23, 2023 16:28
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.

2 participants