bugsnag / bugsnag-flutter

BugSnag crash reporting for Flutter apps
https://docs.bugsnag.com/platforms/flutter/
MIT License
10 stars 8 forks source link

Passing enums as metadata values breaks the reporting #198

Closed behnamsattar closed 11 months ago

behnamsattar commented 1 year ago

Description

When there is an enum value among the metadata values, an error is thrown pointing to stringifying the metadata. This happens with both the .leaveBreadcrumb() and .notify() methods.

Steps to reproduce

I'm sending an OperationType object as a metadata value in my workflow. Underneath, the library struggles with stringifying it. It's a simple enum, but it breaks logging and error reporting! I was able to reproduce this with any enum. As a workaround, currently, I always convert my enum to a string before passing it in.

Environment

Code example:

enum TestEnum {
  value1,
  value2,
  value3,
}

    bugsnag.leaveBreadcrumb(
      'message',
      metadata: {'enum': TestEnum.value1},
      type: BugsnagBreadcrumbType.request,
    );

Error message:

flutter: error: Converting object to an encodable object failed: Instance of 'BugsnagBreadcrumb'
flutter: stackTrace: #0      _JsonStringifier.writeObject (dart:convert/json.dart:793:7)
#1      _JsonStringifier.writeMap (dart:convert/json.dart:874:7)
#2      _JsonStringifier.writeJsonValue (dart:convert/json.dart:829:21)
#3      _JsonStringifier.writeObject (dart:convert/json.dart:784:9)
#4      _JsonStringStringifier.printOn (dart:convert/json.dart:982:17)
#5      _JsonStringStringifier.stringify (dart:convert/json.dart:967:5)
#6      JsonEncoder.convert (dart:convert/json.dart:345:30)
#7      JsonCodec.encode (dart:convert/json.dart:231:45)
#8      JSONMessageCodec.encodeMessage
message_codecs.dart:103
#9      JSONMethodCodec.encodeMethodCall
message_codecs.dart:139
#10     MethodChannel._invokeMethod
platform_channel.dart:304
#11     MethodChannel.invokeMethod
platform_channel.dart:491
#12     ChannelClient.leaveBreadcrumb (package:bugsnag_flutter/src/c<…>
luke-belton commented 1 year ago

Hi @behnamsattar 👋 thanks for raising this - we've reproduced this issue and are investigating. We'll keep you updated on this thread.

As you suggest, a workaround in the meantime is to call toString on your enum value before adding it as metadata.

johnkiely1 commented 11 months ago

Hey @behnamsattar , just to close the loop on this, a fix has been released in v2.5.0.