E0078

E0078#

Warning name: result_error_return

A function returns Result[T, E] even though E is an error type.

For a failable API, prefer MoonBit's error effect, written T raise E. Keep a Result return type only when success and failure are intentionally represented as ordinary data. This migration warning is disabled by default.

Erroneous example#

///|
pub(all) suberror ParseError {
  ParseError
}

///|
pub fn parse_number() -> Result[Int, ParseError] {
  Err(ParseError)
}

Suggestion#

Return the success type and declare the error with raise.

///|
pub(all) suberror ParseError {
  ParseError
}

///|
pub fn parse_number() -> Int raise ParseError {
  raise ParseError
}