I have been struggling to send a custom error from within a flutter isolate.
I followed all the documentation, but I keep getting
Context
This is how I setup my isolates
Future<R> isolateRun<R>(FutureOr<R> Function() callback,
{String? debugName}) async {
final RootIsolateToken? token = RootIsolateToken.instance;
assert(token != null);
Isolate.current.addErrorListener(RawReceivePort((pair) async {
final List<dynamic> errorAndStacktrace = pair;
await FirebaseCrashlytics.instance.recordError(
errorAndStacktrace.first,
errorAndStacktrace.last,
);
}).sendPort);
return await Isolate.run(() async {
BackgroundIsolateBinaryMessenger.ensureInitialized(token!);
DartPluginRegistrant.ensureInitialized();
await initFirebase(); // This is where I call Firebase.initializeApp and define FlutterError.onError and PlatformDispatcher.instance.onError
return callback();
}, debugName: debugName);
} else {
return await computation();
}
}
in the callback, I parse a fairly long JSON list, and my idea was to receive a Crashalytics report whenever one or more of the items in the list would fail parsing.
Something like
await isolateRun<List<Item>>(() {
return jsonDecode(response)
.map<Item?>((tagJson) {
try {
return Item.fromJson(tagJson);
} catch (e) {
getLogger().e("Could not parse this item ID $tagJson['id']}");
FirebaseCrashlytics.instance.recordError(
e,
s,
reason: "Could not parse this item",
information: [tagJson],
);
return null;
}
})
.whereType<Item>()
.toList();
});
However, I have spent a few hours trying all possible combinations, and I keep getting this error whenever I call FirebaseCrashlytics.instance.recordError
[FATAL:flutter/lib/ui/window/platform_message_response_dart_port.cc(53)] Check failed: did_send.
Any idea of the issue? Am I missing something?