Since WasmError encodes all guest errors as a string, we could makes error details easier to parse by encoding as a json object within the message itself. E.g. instead of the js client receiving:
{"name":"internal_error","message":"Source chain error: InvalidCommit error: Recipe needs at least 1 trusted author"}
It could instead receive:
{"name":"internal_error","message":"Source chain error: InvalidCommit error: __ERR_START__{"type":"InvalidRecipe","reasons":[{"type":"NoTrustedAuthors"},{"type":"UndeclaredVar","var_name":"foo"}]}__ERR_END__"}
And to complement this we could generate TS counterparts:
Extracting this information can then be done by parsing the string between the delimiters.
Return ExternResult<SomeNestedTypedResult>
Coordinator functions could return errors as 'successes' to take advantage of builtin msgpack serialisation. One advantage is that is becomes simpler to bind esoteric error type to only their relevant functions.
The biggest flaw with this approach is that most hdk functions already return ExternResult, so we're already forced to be interpreting an error string much of the time.
Some options:
Error details as delimited json string
Since
WasmError
encodes all guest errors as a string, we could makes error details easier to parse by encoding as a json object within the message itself. E.g. instead of the js client receiving:{"name":"internal_error","message":"Source chain error: InvalidCommit error: Recipe needs at least 1 trusted author"}
It could instead receive:{"name":"internal_error","message":"Source chain error: InvalidCommit error: __ERR_START__{"type":"InvalidRecipe","reasons":[{"type":"NoTrustedAuthors"},{"type":"UndeclaredVar","var_name":"foo"}]}__ERR_END__"}
And to complement this we could generate TS counterparts:
Extracting this information can then be done by parsing the string between the delimiters.
Return
ExternResult<SomeNestedTypedResult>
Coordinator functions could return errors as 'successes' to take advantage of builtin msgpack serialisation. One advantage is that is becomes simpler to bind esoteric error type to only their relevant functions.
The biggest flaw with this approach is that most hdk functions already return
ExternResult
, so we're already forced to be interpreting an error string much of the time.