Skip to content

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
Collaborator

@stuartmorgan-g stuartmorgan-g 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
Collaborator

@stuartmorgan-g stuartmorgan-g 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.

Copy link
Collaborator

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 force-pushed the channel-name-in-flutter-error branch from 75da08e to 38a21e2 Compare November 10, 2023 19:49
@tarrinneal tarrinneal force-pushed the channel-name-in-flutter-error branch from 38a21e2 to ec72ad4 Compare November 10, 2023 20:30
@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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 13, 2023
@reidbaker reidbaker mentioned this pull request Jan 12, 2024
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