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

Improve error message when unpacking non-string keys into an object #127

Open
LilyFoote opened this issue Jan 10, 2024 · 3 comments
Open

Comments

@LilyFoote
Copy link

LilyFoote commented Jan 10, 2024

I'm using msgpack to serialize python data and then I want to unpack that again in my typescript code. In msgpackr 1.9.9 I was able to unpack a map that had keys that were a custom extension type (e.g. a python tuple or frozenset) I had defined. Upgrading to 1.10.1 I started seeing the Invalid property type for record error added in 18f44f8.

As discussed below, setting mapsAsObjects: false preserves the original key type. Perhaps this error message could be updated to something like:

Non-string object key. Try using mapsAsObjects: false

@kriszyp
Copy link
Owner

kriszyp commented Jan 12, 2024

Just to clarify a bit, you are not reading decoding the MessagePack as JS Maps using mapsAsObjects: false, you are decoding them as plain JS objects? And is the latter the preference? Decoding as Map , should still preserve the original key type.

@LilyFoote
Copy link
Author

Ah! I didn't realise that was the appropriate way to do this. I'll give that a try next week. If that works, I'd suggest updating the error message to point at that as a way to fix the problem.

@LilyFoote LilyFoote changed the title Add support for unpacking map keys that aren't strings or numbers Improve error message when unpacking non-string keys into an object Jan 15, 2024
@LilyFoote
Copy link
Author

I just realised I never got back to you here. Using mapsAsObjects: false did indeed resolve the issue for me. My suggestion to improve the error message to point at this solution still stands.

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

No branches or pull requests

2 participants