-
Notifications
You must be signed in to change notification settings - Fork 29.2k
Description
Hello,
I'm writing the Swift part of our application, and I need to return additional error details to the Dart part.
To that end, I wanted to use FlutterError
, which has a details
field.
However, the following code fails:
completion(Result.failure(FlutterError(code: "someCode", message: "msg", details: 42)))
and I get this error:
Swift Compiler Error (Xcode): 'FlutterError' is not convertible to 'any Error'
I dug up a bit, and came across the wrapError
function in the generated Swift code:
private func wrapError(_ error: Any) -> [Any?] {
if let flutterError = error as? FlutterError {
return [
flutterError.code,
flutterError.message,
flutterError.details
]
}
return [
"\(error)",
"\(type(of: error))",
"Stacktrace: \(Thread.callStackSymbols)"
]
}
So it seems that the only way to get additional info passed to Dart is to return a FlutterError
, which doesn't seem to implement the Error
protocol.
I can workaround that for the time being by returning an ad-hoc structure. From what I understand, the Objective-C generator supports FlutterError since a few versions, was there an oversight on the Swift one?