wapc / as-msgpack

MessagePack package for AssemblyScript
Apache License 2.0
13 stars 7 forks source link

Implement a SafeDecoder #9

Closed maximebedard closed 2 years ago

maximebedard commented 3 years ago

This is a workaround for the lack of support of exceptions in Assemblyscript. I'm adding a SafeDecoder that returns a Result<T, Error> instead of throwing errors. This is especially useful to us to build hierarchical error (e.g. key foo doesn't exist in toto.bar) within deeply nested structures.

I've made sure to preserve compatibility with the previous API by exposing a Decoder that internally uses the SafeDecoder, but unwrap every errors.

I've also added a few missing test cases and fixed a bug revealed by the added tests for Sizer.writeArray.

Let me know what you think!

pkedy commented 2 years ago

Thanks for submitting this. Working around the lack of exceptions in AS was added a while back (kinda sorta like this) and I believe is incorporated in the latest @wapc/codegen.