-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
ObjectAnnotation is incorrect after returning an error in a custom decoder #1224
Comments
Also picked up that if one changes from
|
Thanks for opening this ticket and writing up the extensive report. I will take a look at this soon. Bit of busy this weekend, so it will likely be next week. |
Hi @craig-feldman! I finally had the time to investigate here, but I cannot seem to replicate the issue myself. Your decoder definitions seems right to me, no issues there. I added the test case expectations and code snippet you shared to the test suite but… they are all passing for me when I try it 🤔 |
One theoretical way there an issue like this could get created might be if somehow you have multiple versions of decoders that are being mixed. Can you confirm you only have one version of decoders installed? npm ls decoders Does this report more than 1 version by any chance? |
That's for following up on this @nvie . Can confirm that replicating that test case for us also passes. The issue may have to do with our project structure and setup. We use pnpm workspaces and a monorepo. We have defined the
However, when we change that to an absolute/relative import e.g. Can confirm that we only have references to |
If there are only 2.6 versions, it's still possible to end up with multiple copies of decoders in your bundle, if somehow (due to your configuration) you end up in your bundle with both a CJS and an ESM "copy" of decoders. The reason it's causing issues is that decoders uses a module level weakset to track whether a value is an Annotation or not (without having to look at or rely on the presence of specific fields). This weakset is supposed to be global singleton, but if you have two copies of decoders in your bundle (one from the CJS and one from the ESM module) then annotations created by the CJS "copy" will not be recognized by the ESM "copy" as such. In those cases, the annotations are recognized as a user value incorrectly. So then it would be annotating the annotation instead of the input object. I think this is what you're seeing, and it's absolutely a bug. I've provided two potential ways to fix this. Would you be able to try these out and see which one fixes your issue best?
Curious to hear which of these will best fix your issue! Thanks again for highlighting this issue and reporting it 🙏 |
Thank you for the detailed feedback @nvie! I was thinking that it might have something to do with the |
Description of the bug
When using the
define
decoder and returning an error, the resultant error generated after calling this custom decoder with invalid input seems incorrect. This happens when the custom decoder returns the error generated from a built in decoder.Expected behavior
Returning an error in this case should result in the same error being thrown when calling this custom decoder.
To Reproduce
We have a custom decoder defined as follows for combining objects:
This can be called as follows:
The first console log (where we return the error) produces a correctly formatted error:
but at the second console log, the error looks incorrect:
Additional context
Decoders version: 2.6.0
TypeScript version: 5.7.3
Flow version: NA
Node version: 20.18.2
This was working for us before in version 2.0.3
The text was updated successfully, but these errors were encountered: