Concordium / concordium-contracts-common

Common functionality used by smart contracts and the host environment on the Concordium blockchain.
Mozilla Public License 2.0
10 stars 10 forks source link

Improve error reporting when serializing JSON using schema #68

Closed Bargsteen closed 1 year ago

Bargsteen commented 1 year ago

Description

We could improve the error reporting when converting JSON parameters to binary using a schema in concordium-contracts-common. By improve, I mean that we could include a "stacktrace" to show where the incorrect value belongs. This is especially useful when the parameter is a struct or enum comprised of many fields.

So instead of giving the error Expected AccountAddress. It should tell you this, but also include information about where it expects an account address. Similar to what concordium-client does:

Error: Could not decode parameters from file 'param.json' as JSON:
       Expected value of type "<AccountAddress>", but got: 123.
       In [
           123
       ].
       In enum variant '"Account"'.
       In field 'operator'.
       In {
           "operator": {
               "Account": [
                   123
               ]
           },
           "update": {
               "Remove": []
           }
       }.
       In [
           {
               "operator": {
                   "Account": [
                       123
                   ]
               },
               "update": {
                   "Remove": []
               }
           }
       ].

Since the JavaScript SDKs recently started using concordium-contracts-common for handling the JSON to binary conversion, this issue has become more important.

abizjak commented 1 year ago

The serial_value method on Type now returns a meaningful error which can be rendered as a stack trace.