archethic-node
archethic-node copied to clipboard
SC: Add new keyword to return explicit error
Is your feature request related to a problem?
Since new public function are available through API, we would need to have a standard way for them to return errors. This would be usefull for Dapps requesting data that could easily handle errors or valid response
Describe the solution you'd like
As we now uses Json RPC specification we could have the same behavior for returning error. examples:
// This is a valid response
{
"jsonrpc": "2.0",
"id": 1,
"result": "SC function result" //could be any type
}
// This is an error response
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": 240, // code for function returning error
"message": "Function execution returned an error",
"data": {
"contractErrorCode": 1234, // error code specified by contract developer
"contractErrrorMessage": "SC error message",
"contractErrorData": "optionnal data"
}
}
}
This approach keeps the Json RPC way and allow lots of possibility for developer to return understandable error
To achieve this a new keyword should be added in SC language to return the error. This keyword would stop the contract execution whenever it is in function, conditions or actions block.
We could use throw
keyword for example (we may change its name)
export function valid_params?(params) do
if Json.valid?(params) do
...
else
throw 123, "params is not valid json", "additionnal data"
end
end
Additional context
No response
Epic
No response