error fail-type
What it means#
fail e returns the error e from the function, so the type of e MUST be part of the declared return type; the same holds for errors propagated with e? (§6.5). The return type must be a union that mentions the error type explicitly.
Example#
@error data NotFound { what: str }
fn find(id: u64) -> str | NotFound {
fail Timeout // <- fail-type
}error
fail-type
How to fix#
@error data NotFound { what: str }
fn find(id: u64) -> str | NotFound {
fail NotFound{ what: "user" }
}Fail with an error from the declared set, or extend the return type (-> str | NotFound | Timeout).