-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: bigint coerce crash #3822
base: main
Are you sure you want to change the base?
fix: bigint coerce crash #3822
Conversation
✅ Deploy Preview for guileless-rolypoly-866f8a ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
deno/lib/types.ts
Outdated
try { | ||
input.data = BigInt(input.data); | ||
} catch { | ||
input.data = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here should return INVALID instate of undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works and looks more correct 👍🏻
src/types.ts
Outdated
try { | ||
input.data = BigInt(input.data); | ||
} catch { | ||
input.data = undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe here should return INVALID instate of undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works and looks more correct 👍🏻
Discovered when parse is executed through
isOptional
check onZodBigInt
which adds aundefined
safeParse execution to look for errors, it crashes when attempting to addundefined
to BigInt as its an invalid value.One fix here is to just try catch the instantiation and cast the coerced value to
undefined
if it throws and error. This way all parser checks will fail on invalid values but not crash on internal checks which provides undefined as the input value.Perhaps another approach could be to just catch and ignore the error and let the input data checks to subsequently verify that the input value is valid. 🤔
closes #3821