E4127

E4127#

类型不是错误类型。

MoonBit only allow error types (defined with type! keyword) to appear after the exclamation mark (!) in the return type of a function.

错误示例#

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.
}

建议#

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")
}