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.
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.
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!