Skip to content

[pigeon] asserts when java platform throws NPE. #67586

@bsutton

Description

@bsutton

@gaaclarke
I'm using pigeon 0.10.0.

When calling a platform method that generates an NPE (on the platform side) the pigeon code is generating an assert:

2020-10-08 11:12:46.626 6638-6672/com.bsutton.sounds.sounds_example E/flutter: [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: 'package:flutter/src/services/message_codec.dart': Failed assertion: line 111 pos 15: 'code != null': is not true.
    #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)
    #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
    #2      new PlatformException (package:flutter/src/services/message_codec.dart:111:15)
    #3      SoundsToPlatformApi.startPlayer (package:sounds_platform_interface/sounds_platform_interface.dart:868:13)

The pigeon code generates:

  }
  private static HashMap wrapError(Exception exception) {
    HashMap<String, Object> errorMap = new HashMap<>();
    errorMap.put("message", exception.toString());
    errorMap.put("code", null);
    errorMap.put("details", null);
    return errorMap;
  }

As you can see the generated code sets put("code", null) which the core messages_code class does not accept.

My suggestion would be to set 'code' to be the simple name of the exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: proposalA detailed proposal for a change to Flutterp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions