Closed narcodico closed 3 months ago
Thanks for opening an issue!
The issue with this approach is the signature of onError
will just become Function
(completely untyped). I understand it's consistent with existing APIs like Future.catchError
and Completer.completeError
but those APIs are likely the way they are because they pre-date a lot of modern Dart language features so I'm a bit torn about making this change since in some ways it feels like a regression in terms of API from a type-safety standpoint.
I was exploring the possibility of simplifying the signature, but you're right. The nearest supertype of both void Function(Object)
and void Function(Object, StackTrace)
is Function
, but you end up loosing type-safety.
Description
The error handler signature on
Emitter
's methods isvoid/State Function(Object error, StackTrace stackTrace)?
. There are situations when using a custom error/exception/failure that could potentially encapsulate the stack, deems theStackTrace
parameter useless. To better align with some other APIs likeFuture.catchError
,Completer.completeError
and even the corecatch
signature which accepts an optionalStackTrace
, I would like to see theStackTrace
converted to an optional parameter.Desired Solution
Make the
StackTrace
parameter optional and enable usingonError
in a cleaner way, e.g.: