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] ArgumentError when using a Map with enum keys #93464

Closed
gianlucaparadise opened this issue Nov 11, 2021 · 3 comments
Closed

[pigeon] ArgumentError when using a Map with enum keys #93464

gianlucaparadise opened this issue Nov 11, 2021 · 3 comments
Labels
found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: pigeon related to pigeon messaging codegen tool P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. r: duplicate Issue is closed as a duplicate of an existing issue team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team

Comments

@gianlucaparadise
Copy link

gianlucaparadise commented Nov 11, 2021

Steps to Reproduce

  1. Define an enum YourEnum
  2. Define a class YourObject with a Map<YourEnum?,String?> field
  3. Define a pigeon API with a method that takes YourObject as input
  4. Create an instance of YourObject, fill the map field and call your method
  5. Error: The MessageCodec is not able to encode your argument

You can also check this repository with a sample app:

  1. Clone the repo
  2. Run the tests under test/pigeon_test.dart

Expected results: I expected to use a Map with enum as key

Actual results: The Map can't be encoded

Code sample

Pigeon API definition:

enum MessageKey {
  title,
  subtitle,
  description,
}

class Message {
  int? id;
  Map<MessageKey?, String?>? additionalProperties;
}

@HostApi()
abstract class HostApiBridge {
  void sendMessage(Message message);
}

API use:

final api = HostApiBridge();

Message message = Message()
  ..id = 1
  ..additionalProperties = {
    MessageKey.title: "title",
    MessageKey.subtitle: "subtitle",
    MessageKey.description: "description",
  };

api.sendMessage(message);

A working sample is available in this repository.

Logs
Invalid argument: Instance of 'MessageKey'

When the exception was thrown, this was the stack:
#0      StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:426:7)
#1      _HostApiBridgeCodec.writeValue (package:pigeon_issue_example/host_api.dart:45:13)
#2      StandardMessageCodec.writeValue.<anonymous closure> (package:flutter/src/services/message_codecs.dart:422:9)
#3      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:400:8)
#4      StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:421:13)
#5      _HostApiBridgeCodec.writeValue (package:pigeon_issue_example/host_api.dart:45:13)
#6      StandardMessageCodec.writeValue.<anonymous closure> (package:flutter/src/services/message_codecs.dart:423:9)
#7      _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:400:8)
#8      StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:421:13)
#9      _HostApiBridgeCodec.writeValue (package:pigeon_issue_example/host_api.dart:45:13)
#10     _HostApiBridgeCodec.writeValue (package:pigeon_issue_example/host_api.dart:42:7)
#11     StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:416:9)
#12     _HostApiBridgeCodec.writeValue (package:pigeon_issue_example/host_api.dart:45:13)
#13     StandardMessageCodec.encodeMessage (package:flutter/src/services/message_codecs.dart:314:5)
#14     BasicMessageChannel.send (package:flutter/src/services/platform_channel.dart:56:71)
#15     HostApiBridge.sendMessage (package:pigeon_issue_example/host_api.dart:75:23)
#16     main.<anonymous closure> (file:///Users/your.name/mydev/pigeon_issue_sample/pigeon_issue_example/test/pigeon_test.dart:25:9)
#17     main.<anonymous closure> (file:///Users/your.name/mydev/pigeon_issue_sample/pigeon_issue_example/test/pigeon_test.dart:14:49)
#18     testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:176:29)
<asynchronous suspension>
<asynchronous suspension>
(elided one frame from package:stack_trace)

Flutter Analyze:

Analyzing pigeon_issue_example...                                       
No issues found! (ran in 3.0s)
[✓] Flutter (Channel stable, 2.5.2, on macOS 11.6.1 20G224 darwin-x64, locale en-GB)
    • Flutter version 2.5.2 at /Users/gianluca.paradiso/flutter-sdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 3595343e20 (6 weeks ago), 2021-09-30 12:58:18 -0700
    • Engine revision 6ac856380f
    • Dart version 2.14.3

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/gianluca.paradiso/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/gianluca.paradiso/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.4, Build version 12D4e
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

[✓] IntelliJ IDEA Ultimate Edition (version 2020.3.2)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.28.0

[✓] Connected device (2 available)
    • Nexus 5X (mobile) • 02628c9c66bfd34f • android-arm64  • Android 8.1.0 (API 27)
    • Chrome (web)      • chrome           • web-javascript • Google Chrome 95.0.4638.69

• No issues found!
@danagbemava-nc danagbemava-nc added the in triage Presently being triaged by the triage team label Nov 11, 2021
@danagbemava-nc
Copy link
Member

Reproducible using sample provided by OP above.

/cc @gaaclarke

flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-arm, locale en-GB)
    • Flutter version 2.5.3 at /Users/nexus/dev/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (4 weeks ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.0, Build version 13A233
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.28.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 11.6 20G165 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 95.0.4638.69

• No issues found!
[✓] Flutter (Channel master, 2.6.0-12.0.pre.688, on macOS 11.6 20G165 darwin-arm, locale en-GB)
    • Flutter version 2.6.0-12.0.pre.688 at /Users/nexus/dev/sdks/flutters
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f7053eb8ba (8 hours ago), 2021-11-10 21:31:32 -0500
    • Engine revision d5cadd28b0
    • Dart version 2.15.0 (build 2.15.0-285.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/nexus/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] VS Code (version 1.62.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.28.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 11.6 20G165 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 95.0.4638.69

• No issues found!

@danagbemava-nc danagbemava-nc added found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: first party package flutter/packages repository. See also p: labels. p: pigeon related to pigeon messaging codegen tool and removed in triage Presently being triaged by the triage team labels Nov 11, 2021
@stuartmorgan stuartmorgan added the P2 Important issues not at the top of the work list label Nov 16, 2021
@flutter-triage-bot flutter-triage-bot bot added team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team labels Jul 8, 2023
@gnprice
Copy link
Member

gnprice commented Mar 26, 2024

Based on flutter/packages#527, it looks like there were two issues here:

So, closing this issue — it's partly been fixed, and what's left is now a duplicate of #133728.

@gnprice gnprice closed this as completed Mar 26, 2024
@danagbemava-nc danagbemava-nc added the r: duplicate Issue is closed as a duplicate of an existing issue label Mar 26, 2024
Copy link

github-actions bot commented Apr 9, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 has reproducible steps The issue has been confirmed reproducible and is ready to work on p: pigeon related to pigeon messaging codegen tool P2 Important issues not at the top of the work list package flutter/packages repository. See also p: labels. r: duplicate Issue is closed as a duplicate of an existing issue team-ecosystem Owned by Ecosystem team triaged-ecosystem Triaged by Ecosystem team
Projects
None yet
Development

No branches or pull requests

5 participants