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

Make BaseError#walk tolerant to an undefined cause #2954

Merged
merged 2 commits into from
Nov 3, 2024

Conversation

alcuadrado
Copy link
Contributor

@alcuadrado alcuadrado commented Nov 1, 2024

I had an issue where I was setting Error.cause to undefined, and viem was giving me some errors because it was trying to access an undefined. This PR fixes it.


PR-Codex overview

This PR focuses on improving the BaseError#walk method to handle cases where the cause property is undefined, ensuring it doesn't throw errors in such scenarios.

Detailed summary

  • Modified the logic in BaseError#walk to check if err.cause is not undefined before recursively calling walk.
  • Added a test case to verify that walk correctly handles an error with an undefined cause.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Copy link

vercel bot commented Nov 1, 2024

@alcuadrado is attempting to deploy a commit to the Wevm Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

changeset-bot bot commented Nov 1, 2024

🦋 Changeset detected

Latest commit: 7e9d5b3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -87,7 +87,7 @@ function walk(
fn?: ((err: unknown) => boolean) | undefined,
): unknown {
if (fn?.(err)) return err
if (err && typeof err === 'object' && 'cause' in err)
if (err && typeof err === 'object' && 'cause' in err && err.cause !== undefined)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure this doesn't pass the linter, but I had some installation issues. Sorry about that.

@jxom jxom merged commit 4f931a5 into wevm:main Nov 3, 2024
8 of 15 checks passed
@github-actions github-actions bot mentioned this pull request Nov 3, 2024
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