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 Flow Error Handling #17519

Merged

Conversation

connorwinston
Copy link
Member

@connorwinston connorwinston commented Feb 15, 2023

Description

Fixes #15291, Fixes #14415, Closes #16166

This validates that the result of an operation is valid serializable JSON, fixes errors being swallowed because they are enumerable, fixes the request operations error being inconclusive, and adds the ability for operations to throw JSON string errors and them to be parsed before being pushed as an error.

Type of Change

  • Bugfix
  • Improvement
  • New Feature
  • Refactor / codestyle updates
  • Other, please describe:

Requirements Checklist

  • New / updated tests are included
  • All tests are passing locally
  • Performed a self-review of the submitted code

If adding a new feature:

  • Documentation was added/updated. PR:

@connorwinston connorwinston requested review from a team, rijkvanzanten, br41nslug and Nitwel and removed request for a team February 16, 2023 20:24
@connorwinston connorwinston self-assigned this Feb 16, 2023
@connorwinston connorwinston marked this pull request as ready for review February 16, 2023 20:25
api/src/flows.ts Outdated Show resolved Hide resolved
Copy link
Member

@br41nslug br41nslug left a comment

Choose a reason for hiding this comment

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

Works like a charm! But from a security standpoint I am wondering about whether we should dump the entire error stack here 🤔 Perhaps we should only persist the error message itself.
image

@connorwinston
Copy link
Member Author

Works like a charm! But from a security standpoint I am wondering about whether we should dump the entire error stack here 🤔 Perhaps we should only persist the error message itself.

I was curious about that too, but thought that was the intended behavior since the error was just dumped into it before...it just couldn't stringify it because it was enumerable. Which resulted in inconsistent errors because Axios errors some keys are enumerable and some are not. Etc. @rijkvanzanten do you want the full errors returned?

@paescuj paescuj added the API label Feb 28, 2023
@paescuj
Copy link
Member

paescuj commented Mar 2, 2023

Works like a charm! But from a security standpoint I am wondering about whether we should dump the entire error stack here 🤔 Perhaps we should only persist the error message itself. image

Are you worried about the paths? In this case we could use https://github.com/sindresorhus/clean-stack to clean up the stack.

Edit: Let's not block the pull request by this concern and rather track it separately 👍

@br41nslug
Copy link
Member

@paescuj The path i would consider unintended information disclosure yeah but it is also not very readable in this format when all you really need is TypeError: Converting circular structure to JSON

@paescuj
Copy link
Member

paescuj commented Mar 2, 2023

@paescuj The path i would consider unintended information disclosure yeah but it is also not very readable in this format when all you really need is TypeError: Converting circular structure to JSON

Agree very much! I'm going to create a separate issue for this 👍

@paescuj paescuj requested review from br41nslug and a team and removed request for a team March 2, 2023 12:20
@connorwinston
Copy link
Member Author

@br41nslug Not every Operation throws an instance of error, though when it errors. For example, the webhook/request operation. This PR also fixed returning the request instead of the result. The only way to do that with Axios was to make some custom error throwing and catching as a string and then parsing it. Your change breaks the changes made to that. Additionally, in almost every other place, we return errors as JSON objects; however, your change returns a string which may confuse people using flows?

@br41nslug
Copy link
Member

Thanks @connorsimply I may have been a little overzealous on the friday fix there. Have updated it to only apply in the case of an actual Error and use the existing logic otherwise

@connorwinston
Copy link
Member Author

connorwinston commented Mar 6, 2023

@br41nslug @paescuj Are we good then to merge now? Tested your changes and they LGTM!

@br41nslug
Copy link
Member

@connorsimply Yep I think so

@paescuj

This comment was marked as outdated.

api/src/operations/request/index.ts Outdated Show resolved Hide resolved
packages/shared/src/utils/is-valid-json.ts Outdated Show resolved Hide resolved
api/src/flows.ts Outdated Show resolved Hide resolved
packages/shared/src/utils/is-valid-json.test.ts Outdated Show resolved Hide resolved
api/src/flows.ts Outdated Show resolved Hide resolved
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
api/src/flows.ts Outdated Show resolved Hide resolved
@connorwinston
Copy link
Member Author

@paescuj Is this clear to be merged now?

api/src/flows.ts Outdated Show resolved Hide resolved
@paescuj
Copy link
Member

paescuj commented Mar 13, 2023

@paescuj Is this clear to be merged now?

Looks good from my side now 👍 Glad if you could take a final look at it again! 😃

Copy link
Member Author

@connorwinston connorwinston left a comment

Choose a reason for hiding this comment

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

LGTM!

@connorwinston connorwinston enabled auto-merge (squash) March 15, 2023 08:28
@connorwinston connorwinston merged commit 34acd97 into main Mar 15, 2023
5 checks passed
@connorwinston connorwinston deleted the connor/eng-200-run-script-return-value-with-circular branch March 15, 2023 08:29
@licitdev licitdev added this to the Next Release milestone Mar 15, 2023
meditadvisors pushed a commit to ciso360ai/directus-mod that referenced this pull request May 13, 2023
* Validate Operation Result is Serializable

* Enumerate Flow Error Object so it gets logged

* Add ability for error to be a JSON string and parse it

* Make the request operation throw useful error

* Revert DockerCompose in "Validate Operation Result is Serializable"

This partially reverts commit c7e7671.

* Fix Typescript Errors

* Move isValidJSON to Shared Util and add Tests

* return the error message excluding stack trace

* allow for non-exception errors

* Apply suggestions from code review

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>

* Clean-up after wrong suggestion

* Clean-up processing of error data

* Use content-type json if body is object

* Reformat error data check

---------

Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: Brainslug <tim@brainslug.nl>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
5 participants