prologin/stechec2

High level error interfaces

remi-dupre opened this issue · 2 comments

In Rust, it is idiomatic to use the Result type to propagate errors. I don't know many other high level languages but I guess some of them also have convenient built-in structures that we could use.

In Rust this would mean wrapping any type that can represent an error inside a Result<_, _> .

To illustrate the example in Rust, we currently generate this kind of API:

enum Error {
    AnError,
    OtherError,
    Ok,
}

enum Something {
    Result1,
    Result2,
    ErrorSomething,
}

fn action(...) -> Error { ... }
fn get_something(...) -> Something { ... }

Ideally, it would be nice to generate something like that:

enum Error {
    AnError,
    OtherError,
}

enum Something {
    Result1,
    Result2,
}

fn action(...) -> Result<(), Error> { ... }

// We probably don't want to do that as it would require to make
// the interface more complex for some languages.
fn get_something(...) -> Result<Something, Error> { ... }
// or
fn get_something(...) -> Result<Something, ()> { ... }

#159 generalizes this idea to all languages and proposes a concrete proposal for implementation.