E4127#
Type is not an error type.
MoonBit only allow error types (defined with type!
keyword) to appear after
the exclamation mark (!
) in the return type of a function.
Erroneous example#
pub fn may_raise_error() -> Unit!String {
// ^~~~~~
// Error: Type String is not an error type.
raise "Failed" // Error: Type String is not an error type.
}
Suggestion#
You can wrap the type you wish to raise in a error type:
type! StringError String
pub fn may_raise_error() -> Unit!StringError {
raise StringError("Failed")
}