Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SC: Handle library functions error #1197

Open
Neylix opened this issue Jul 27, 2023 · 0 comments
Open

SC: Handle library functions error #1197

Neylix opened this issue Jul 27, 2023 · 0 comments
Labels
feature New feature request smart contracts Involve smart contracts

Comments

@Neylix
Copy link
Member

Neylix commented Jul 27, 2023

Is your feature request related to a problem?

As we are developing a smart contract language, we need to think about error and exception.
In our case there is 3 kind of errors

  • user input error: a user called a smart contract with wrong parameter (wrong type)
  • process error: error that are handled by the code such a network issue
  • unexpected error: error raises by the system (division by 0)

I take the example of the function Json.path_extract(). Currently there is multiple behavior:

  • If the json in input is invalid it raise a Jason.DecodeError which stop the contract execution and return contract_failure
  • If the json is valid and path exists it return the value
  • If the json is valid but path doesn't exist it return an empty string ""

There is some weird behavior with this, for example if the return is an empty string, is it because the path doesn't exist or the path exist and the value is an empty string {"key": ""} ?
And if it raise, we only have contract_failure without idea of what sent wrong while we could provide information

Describe the solution you'd like

There is multiple possibility to resolve this issue.
As elixir all function could return something like {:ok, result} or {:error, reason}. But since the language is designed to be simple this will need pattern matching to be easy to handle or we'll need to have a lot of if statement.

An other solution would be the erlang way "let it crash" but with understandable and well catched error.
For example the function Json.path_extract could throw 2 errors: Invalid json or Path not found. Those error would be catched by the interpreter as a library function error and return an appropriate error to be displayed to the user.

Indeed the last solution impose to have function allowing the user to control the input, in this case the user can use Json.is_valid? and Json.path_match? to be sure the execution of Json.path_extract will not fail

Additional context

No response

Epic

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request smart contracts Involve smart contracts
Projects
Status: Todo 🚩
Development

No branches or pull requests

1 participant