mapErr method

  1. @override
Err<T> mapErr(
  1. @noFutures Err<T> noFutures(
    1. Err<T> err
    )
)
override

Transforms the inner Err instance if this is an Err.

Implementation

@override
@pragma('vm:prefer-inline')
Err<T> mapErr(@noFutures Err<T> Function(Err<T> err) noFutures) {
  // Absorb throws from the user callback so `Err.mapErr` honours the
  // package-wide "no throws outside @unsafeOrError" contract. `on Err
  // catch` preserves a user-thrown `Err` verbatim — statusCode and
  // breadcrumbs survive intact.
  try {
    return noFutures(this);
  } on Err catch (err) {
    return err.transfErr<T>();
  } catch (error, stackTrace) {
    return Err<T>(error, stackTrace: stackTrace);
  }
}