Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pigeon] Channel name in flutter error. #5273

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

tarrinneal
Copy link
Contributor

@tarrinneal tarrinneal commented Oct 31, 2023

Adds the channel name in the connection error message on all platforms host and flutter api methods.

Also fixes a bug with error handling for swift flutter api void methods.

Also adds method to all generators to help clean up duplicated code.

fixes flutter/flutter#136277

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't think about this before: hard-coding all of these strings in the generated code will unnecessarily bloat the size of the binary, because each unique string will end up as data in the compiled output. For all languages, we should be using string interpolation so that we aren't creating N new strings constants.

And while compilers would probably handle de-duping for us if we inline them separately, it would be better not to rely on that and avoid duplicating even separate constants, so ideally we should have the generation output something like (example in Dart, but similar for the other languages):

const String channelName = "big string constant here, once";
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
        channelName,
        codec,
        binaryMessenger: _binaryMessenger);
...
      throw PlatformException(
        code: 'channel-error',
        message:
            'Unable to establish connection on channel: "$channelName".',
      );

@tarrinneal
Copy link
Contributor Author

Sorry I didn't think about this before: hard-coding all of these strings in the generated code will unnecessarily bloat the size of the binary, because each unique string will end up as data in the compiled output. For all languages, we should be using string interpolation so that we aren't creating N new strings constants.

And while compilers would probably handle de-duping for us if we inline them separately, it would be better not to rely on that and avoid duplicating even separate constants, so ideally we should have the generation output something like (example in Dart, but similar for the other languages):

const String channelName = "big string constant here, once";
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
        channelName,
        codec,
        binaryMessenger: _binaryMessenger);
...
      throw PlatformException(
        code: 'channel-error',
        message:
            'Unable to establish connection on channel: "$channelName".',
      );

Makes sense, I made sure to do that in the generators themselves, but I didn't even think about it for the generateds.

This is also a general issue with the duplication of code in the generated files. Something that I'm hoping to tackle some day...

@tarrinneal tarrinneal force-pushed the channel-name-in-flutter-error branch 2 times, most recently from 245f947 to 59e32ad Compare November 3, 2023 16:54
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor changes (some optional). If you want me to re-review the C++ helper change let me know.

@@ -25,6 +25,13 @@ using flutter::EncodableList;
using flutter::EncodableMap;
using flutter::EncodableValue;

FlutterError CreateConnectionError(const std::string channel_name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should either be static or in a namespace { ... } (i.e., an anonymous namespace).

@tarrinneal tarrinneal added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 10, 2023
@auto-submit auto-submit bot merged commit da3bf27 into flutter:main Nov 10, 2023
80 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 13, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 13, 2023
flutter/packages@a682189...17bd92e

2023-11-11 [email protected] Only run tests on macOS 12 (flutter/packages#5369)
2023-11-10 [email protected] [pigeon] Channel name in flutter error. (flutter/packages#5273)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
HugoOlthof pushed a commit to moneybird/packages that referenced this pull request Dec 13, 2023
Adds the channel name in the connection error message on all platforms host and flutter api methods.

Also fixes a bug with error handling for swift flutter api void methods.

Also adds method to all generators to help clean up duplicated code.

fixes flutter/flutter#136277
@reidbaker reidbaker mentioned this pull request Jan 12, 2024
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
Adds the channel name in the connection error message on all platforms host and flutter api methods.

Also fixes a bug with error handling for swift flutter api void methods.

Also adds method to all generators to help clean up duplicated code.

fixes flutter/flutter#136277
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pigeon] Log channel in connection errors
3 participants