gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source.
https://gno.land/
Other
880 stars 364 forks source link

Support returning `error` types from a realm #416

Open moul opened 1 year ago

moul commented 1 year ago

Today, it returns a string representation of the pointer.

It should instead return a structure that can be processed dynamically, containing as much helpful information as possible.

The ultimate goal is to start having official typed errors that can be used by wallets and frontends to react differently, i.e., supporting "redirect errors".

moul commented 1 year ago

Related with #439

jefft0 commented 10 months ago

Hi @moul. I wonder if this is related to a question we have. In GnoMobile, if BroadcastTxCommit, returns an error in bres.CheckTx.Error, then it wraps a meaningful error type such as std.OutOfGasError. (Because the error is generated by the local checks before broadcasting?) We can check the error type. But if it returns an error in bres.DeliverTx.Error then it just wraps the generic abci.StringError. (Because only an error string is returned from the validator?)

For example when we try to register a user without enough "send", it returns the string "payment must not be less than 200000000". In GnoMobile, we would like to return an error code, but it is not ideal to have to match an error message string. (This example is realm-specific, but even language-level errors like nil pointer are just returned as strings.) I ask this question in this issue because maybe the validator can return a meaningful error type. Are there plans for that?

moul commented 10 months ago

I propose an hybrid approach: