Skip to content

Change return type in metadata to allow common errors #1207

@athei

Description

@athei

Currently, the metadata defines the return type of a message (or constructor) as exactly the type that is returned by the message itself.

This doesn't allow us to return any error that isn't defined by the contract itself. For example, the dispatch of a contract call to the individual messages is not handled by user code but by code generated by ink! macros. The way how the metadata is defined won't allow ink! to return an error in case a message isn't found (as the return type is defined by user code). The only thing ink! can emit in this case is a trap which prevents the caller from learning about a missing message.

What we should to is define the return type of messages (and constructors) in terms of an enum that allows us to define common errors which are defined within the ABI rather than within user contract code. As long as we only extend the enum and make it clear that one should not match it exhaustively it will be forward compatible:

enum Error<T> {
    Custom(T),
    UnknownMessage,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions