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

refactor: remove error details #5039

Merged
merged 31 commits into from
Sep 11, 2023
Merged

refactor: remove error details #5039

merged 31 commits into from
Sep 11, 2023

Conversation

stefreak
Copy link
Member

@stefreak stefreak commented Sep 7, 2023

What this PR does / why we need it:

Remove the detail property and constructor argument from GardenError.

We did this because there were several issues with the detail property:

  • When instantiating a GardenError, the detail property misled developers in some cases to conclude that the error message has enough information for users: The contents of the detail property are not printed to the screen when an error occurs, and sometimes useful information has not been exposed through the message.
  • The detail property often used to include complex objects, like instances of Garden or the Solver. The error details sometimes have been exposed to the user through the -o yaml and -o json output flags, or serialized to JSON either accidentally or on purpose through the WebSocket interface or the Garden Cloud API. This led to issues ranging from bad user experience because of huge amounts of YAML, to OOM crashes when serializing huge amounts of JSON. This in turn led to very hard to maintain work-arounds like sanitizeValue. One particular big problem with sanitizeValue is that the return type is only known at runtime so we cannot define a correct TypeScript return type.
  • The detail property is of type any by default but there was still a lot of error handling code that relied on particular details to be defined. Due to this issue there were no type errors when changing the details in any way, and that could lead to really hard to understand issues.

We addressed these issues with the following changes:

  • Remove the detail property and constructor argument from the GardenError ABC.
  • In cases where error details were needed to be accessed programmatically, we added the exact type definitions needed in a particular subclass of GardenError. In the error handling code we used instanceof to narrow the type of the error to that subclass, and only then tried accessing the error details.
  • In cases where crucial details were missing from the error message itself, we added them to the error message.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

@stefreak stefreak force-pushed the errors-remove-details branch from 5f222c4 to 77abdfc Compare September 7, 2023 09:53
@stefreak stefreak changed the title improvement: WIP remove error details refactor: remove error details Sep 8, 2023
@stefreak stefreak force-pushed the errors-remove-details branch from faad4bd to d61c15d Compare September 11, 2023 12:43
@stefreak stefreak marked this pull request as ready for review September 11, 2023 12:43
@stefreak stefreak requested review from vvagaytsev and mkhq September 11, 2023 12:43
@vvagaytsev
Copy link
Collaborator

There is one failing test in the CI.

core/src/exceptions.ts Outdated Show resolved Hide resolved
- Throw GardenError of type "test-failed" or "task-failed" when the actual test or task command failed, e.g. with non-zero exit code.
- Do not report "test-failed" or "task-failed" on errors
like Pod eviction and on other Kubernetes API errors.

Co-authored-by: Tim Beyer <[email protected]>
@stefreak stefreak requested a review from vvagaytsev September 11, 2023 14:21
Copy link
Collaborator

@vvagaytsev vvagaytsev left a comment

Choose a reason for hiding this comment

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

Huge thanks for doing this PR! 👍 :)

@stefreak stefreak added this pull request to the merge queue Sep 11, 2023
Merged via the queue into main with commit 4b92210 Sep 11, 2023
@stefreak stefreak deleted the errors-remove-details branch September 11, 2023 15:36
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.

3 participants