-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
While fixing Flutter API call handling in the C++ generator, I wanted to double-check that errors were expressed the same way for Flutter APIs as for Host APIs, and started looking at the other generators. It appears that we just don't have any error handling in that direction. The Dart side just returns the return value directly, and doesn't catch exceptions (as compared with the behavior of FlutterMethodChannel, which catches Dart PlatformExceptions and converts them to its error envelope form, which is basically the same as what we are doing in the other direction in Pigeon now).
It looks like maybe this was intended to be implemented but just never actually done, since the ObjC generator defines a callback for Flutter APIs that has a reply value and an NSError* argument, only one of which would be expected to be set, but AFAICT there is no codepath that will ever pass anything but nil as the NSError*.
So we should:
- Change the Dart generator to:
- wrap the calls to Flutter API implementations in a try/catch for
PlatformException - return successful return values from a Flutter API call in a one-argument array
- return
PlatformExceptionsin a three-argument array
- wrap the calls to Flutter API implementations in a try/catch for
- Change all the other generators to unwrap that array and pass along errors appropriately
- Add an integration test involving returning an error from a Flutter API.