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

#6408: jq error handling improvements #6415

Merged
merged 18 commits into from
Sep 10, 2023
Merged

#6408: jq error handling improvements #6415

merged 18 commits into from
Sep 10, 2023

Conversation

twschiller
Copy link
Contributor

@twschiller twschiller commented Sep 9, 2023

What does this PR do?

Work remaining

  • Adds retry on potentially transient errors: generic error, no stack
  • Improve error message for JSON.parse error in jq-web
  • Fix jq execution errors being wrapped as invalid input errors

Discussion

Future Work

Checklist

  • Add tests
  • Designate a primary reviewer: @mnholtz

@codecov
Copy link

codecov bot commented Sep 9, 2023

Codecov Report

Patch coverage: 85.71% and project coverage change: -0.01% ⚠️

Comparison is base (e237877) 70.08% compared to head (ea9375f) 70.08%.

❗ Current head ea9375f differs from pull request most recent head ff18deb. Consider uploading reports for the commit ff18deb to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6415      +/-   ##
==========================================
- Coverage   70.08%   70.08%   -0.01%     
==========================================
  Files        1167     1167              
  Lines       36403    36431      +28     
  Branches     6852     6860       +8     
==========================================
+ Hits        25512    25531      +19     
- Misses      10891    10900       +9     
Files Changed Coverage Δ
src/utils/promiseUtils.ts 70.31% <83.33%> (+3.00%) ⬆️
src/bricks/transformers/jq.ts 91.30% <86.66%> (-2.03%) ⬇️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

}

if (
(retryError && !error.message.includes(retryError)) ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a better way to compare errors in javascript?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It depends on the error, e.g., depending on the error you might look at the class name. In this case, we do want to compare on the messages.

See comment here: https://github.com/pixiebrix/pixiebrix-extension/pull/6415/files#r1320839837

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this particular scenario, I think want the retry to happen on both on the generic error, and also unexpected end of JSON error. I suspect some of the unexpected end of JSON errors are transient

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good call

retryError?: string
): Promise<T> {
for (let failedAttempts = 0; failedAttempts <= retries; failedAttempts++) {
const delayMs = Math.random() * 100;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Happy to adjust this number as needed. I didn't choose this number for any particular reason, other than the fact that it seemed like a good ballpark number.

src/bricks/util.ts Outdated Show resolved Hide resolved
3,
(error) => {
if (!isErrorObject(error)) {
throw error;
Copy link
Contributor Author

@twschiller twschiller Sep 10, 2023

Choose a reason for hiding this comment

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

The shouldRetry method should not throw. The check should be isErrorObject(error) && (....)

}

return (
error.message.includes(JSON_ERROR) ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leave a comment that we're not retrying on FS_STREAM_ERROR because it's not recoverable. The error kicks in when the jq brick has been run too many times, so retrying won't succeed

@twschiller twschiller changed the title #6408: [WIP] jq error handling fixes #6408: jq error handling improvements Sep 10, 2023
* Return true for jq errors that might be transient.
*
* We're excluding FS_STREAM_ERROR because it most likely indicated emscripten has hit the stream limit, so additional
* retries would not success: https://github.com/fiatjaf/jq-web/issues/18
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* retries would not success: https://github.com/fiatjaf/jq-web/issues/18
* retries would not succeed: https://github.com/fiatjaf/jq-web/issues/18

/**
* Return true for jq errors that might be transient.
*
* We're excluding FS_STREAM_ERROR because it most likely indicated emscripten has hit the stream limit, so additional
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* We're excluding FS_STREAM_ERROR because it most likely indicated emscripten has hit the stream limit, so additional
* We're excluding FS_STREAM_ERROR because it most likely indicates emscripten has hit the stream limit, so additional

*
* JSON_ERROR can be deterministic, but we've also seen some error telemetry indicating it might be transient.
*/
function isTransientError(error: unknown): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This refactor is a huge improvement 👍

@github-actions
Copy link

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

@twschiller twschiller enabled auto-merge (squash) September 10, 2023 23:23
@twschiller twschiller merged commit 74c52f2 into main Sep 10, 2023
@twschiller twschiller deleted the feature/6408-jq-errors branch September 10, 2023 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

End of JSON input error running jq bricks
2 participants