Skip to content

[pigeon] Implement error handling for Flutter API calls #118243

@stuartmorgan-g

Description

@stuartmorgan-g

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 PlatformExceptions in a three-argument array
  • 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.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions