kriszyp / msgpackr

Ultra-fast MessagePack implementation with extension for record and structural cloning / msgpack.org[JavaScript/NodeJS]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

LilyFoote opened this issue · comments

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

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.

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.

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.