Skip to content

ParseError no longer use the error.cause property #2773

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

Closed
tusharf5 opened this issue Jul 14, 2024 · 5 comments · Fixed by #2774
Closed

ParseError no longer use the error.cause property #2773

tusharf5 opened this issue Jul 14, 2024 · 5 comments · Fixed by #2774
Assignees
Labels
bug Something isn't working completed This item is complete and has been merged/shipped parser This item relates to the Parser Utility

Comments

@tusharf5
Copy link
Contributor

Expected Behavior

Earlier the error thrown within the handler would be attached to the ParseError to the .cause property. This no longer is the case. This broke one of our prod services that were relying on this property.

I think it was unintentionally removed as part of dropping Node 16 support.

Here's the link to the change.

e4eee73#diff-27fac689aa83bd57991ab46c30f4cd72584c529baa433ce899e8b7bd6db7a7deL21

Current Behavior

ParseError.cause is undefined

Code snippet

Just throw any validation error in the handler and look for error.cause property.

Steps to Reproduce

You can run any tests in this file "packages/parser/tests/unit/envelope.test.ts" and check for error.cause property. It will be undefined.

Possible Solution

I've submitted a PR which reverts the ParseError change that removed this behaviour.

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

20.x

Packaging format used

npm

Execution logs

No response

@tusharf5 tusharf5 added bug Something isn't working triage This item has not been triaged by a maintainer, please wait labels Jul 14, 2024
Copy link

boring-cyborg bot commented Jul 14, 2024

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #typescript channel on our Powertools for AWS Lambda Discord: Invite link

@dreamorosi dreamorosi added confirmed The scope is clear, ready for implementation parser This item relates to the Parser Utility and removed triage This item has not been triaged by a maintainer, please wait labels Jul 14, 2024
@dreamorosi dreamorosi moved this from Triage to Working on it in Powertools for AWS Lambda (TypeScript) Jul 14, 2024
@dreamorosi
Copy link
Contributor

Hi @tusharf5, thank you for opening this issue.

You are right in that the cause property was removed unintentionally; the change was made because since dropping Node.js 16 we can now safely assume that all errors have the cause property by default.

The idea was to use the "native" property instead of one defined by us, however it seems that I introduced a bug by not propagating the second argument we pass when we throw a ParseError to its parent class here. The error should've been like this:

class ParseError extends Error {
  public constructor(message: string, options?: { cause?: Error }) {
    const errorMessage = options?.cause
      ? `${message}. This error was caused by: ${options?.cause.message}.`
      : message;
-   super(errorMessage);
+   super(errorMessage, options);
    this.name = 'ParseError';
  }
}

Even though the API for this specific utility is still to be considered unstable during its beta period, we should have included this property in our tests.

--

Thank you for submitting the PR to fix it, I've left a couple comments. Once addressed it's good to be merged.

@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in Powertools for AWS Lambda (TypeScript) Jul 15, 2024
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added pending-release This item has been merged and will be released soon and removed confirmed The scope is clear, ready for implementation labels Jul 15, 2024
@dreamorosi
Copy link
Contributor

Hi @tusharf5, the release notes are not yet out but we made a release that includes the fix to this issue.

This should unblock your production workload.

Thanks again for the quick PR.

Copy link
Contributor

This is now released under v2.5.0 version!

@github-actions github-actions bot added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon labels Jul 15, 2024
@dreamorosi dreamorosi moved this from Coming soon to Shipped in Powertools for AWS Lambda (TypeScript) Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working completed This item is complete and has been merged/shipped parser This item relates to the Parser Utility
Projects
Development

Successfully merging a pull request may close this issue.

2 participants