digital-asset / daml

The Daml smart contract language
https://www.digitalasset.com/developers
Other
802 stars 204 forks source link

Improve the error message for users of Daml apps #4872

Open hurryabit opened 4 years ago

hurryabit commented 4 years ago

Currently, the only way to get nice error messages for users of apps written in DAML seems to be to replicate a fair chunk of business logic in the frontend. Catching exceptions coming from the JSON API or Ledger API and displaying them to the user will horrify them.

Here are a few examples:

I think there are a few things we could immediately improve:

My general impression is that it will need a concentrated effort to make this better across the board.

Related to: #3247, #4521

cc @bame-da @gerolf-da @S11001001 @leo-da

leo-da commented 4 years ago

@hurryabit we do not have a way of getting the details of which field in particular was not properly formatted, however in case of invalid JSON, Spray gives us the line and position in the input JSON at which it failed (see 2nd example below).

We should also add some context to our errors. E.g. in case of empty party string, we can say something like this:

Party format error. JsonError: spray.json.DeserializationException: empty string

When submitting a create command we can do:

"CreateCommand format error. JsonError: JsonReaderError. Cannot read JSON: <{\n  \"templateId\": \"Iou:Iou\"xxxx,\n  \"payload\": {\n    \"issuer\": \"Alice\",\n    \"owner\": \"Alice\",\n    \"currency\": \"USD\",\n    \"amount\": \"999.99\",\n    \"observers\": []\n  }\n}>. Cause: spray.json.JsonParser$ParsingException: Unexpected character 'x' at input index 27 (line 2, position 26), expected '}':\n  \"templateId\": \"Iou:Iou\"xxxx,\n                         ^\n"
gerolf-da commented 4 years ago

The error message when a key is not found in the meantime changed to:

Command interpretation error in LF-DAMLe: dependency error: couldn't find key com.daml.lf.transaction.GlobalKey@1c2d82ec

because GlobalKey is not a case class anymore. So it's actually impossible to learn anything about the key.

I also agree with the scary looking error message around user abort.

Both of these issues were recently reported by a customer trying to understand what's going on.

hurryabit commented 4 years ago

The error message when a key is not found in the meantime changed to:

Command interpretation error in LF-DAMLe: dependency error: couldn't find key com.daml.lf.transaction.GlobalKey@1c2d82ec

because GlobalKey is not a case class anymore. So it's actually impossible to learn anything about the key.

That is very bad for debuggability. Do we know why GlobalKey is not a case class anymore? And is there anything we can do to make the message better? cc @remyhaemmerle-da

remyhaemmerle-da commented 4 years ago

GlobalKey is not a case class. We just need to override the toString method to make it nicer.

stefanobaghino-da commented 3 years ago

Needs scoping and design, will become more relevant after the Ledger API adopts the new error codes (scheduled for Nov 2021).