runCatching<R> method

  1. @visibleForTesting
  2. @protected
  3. @override
FutureOr<R?> runCatching<R>(
  1. FutureOr<R?> block(), {
  2. FutureOr<R?> onSuccess(
    1. R data
    )?,
  3. FutureOr<R?> onFailure(
    1. Object e,
    2. StackTrace s
    )?,
  4. @Deprecated('removed, set `Logger.root.level = Level.FINE` or lower to print SkipError') bool ignoreSkipError = true,
  5. int slowlyMs = 0,
  6. Object? debounceTag,
  7. Object? throttleTag,
  8. Object? mutexTag,
})
override

run and catch error, then putError

ref skpIf/skpNull

Implementation

@visibleForTesting
@protected
@override
FutureOr<R?> runCatching<R>(
  FutureOr<R?> Function() block, {
  FutureOr<R?> Function(R data)? onSuccess,
  FutureOr<R?> Function(Object e, StackTrace s)? onFailure,
  @Deprecated(
    'removed, set `Logger.root.level = Level.FINE` or lower to print SkipError',
  )
  ignoreSkipError = true,
  int slowlyMs = 0,
  Object? debounceTag,
  Object? throttleTag,
  Object? mutexTag,
}) => super.runCatching(
  block,
  onSuccess: onSuccess,
  onFailure: (e, s) {
    if (e is SkipError) {
      logger(
        'SKIPPED: ${e.msg}',
        level: e.level,
        logExtra: logExtra,
        // error: e, // do not log SkipError
        stackTrace: e.stackTrace,
      );
      return null;
    }
    final fun =
        onFailure ??
        (e, s) => logger(
          'FAILURE: $e',
          level: Level.WARNING.value,
          logExtra: logExtra,
          error: e,
          stackTrace: s,
        );
    return fun.call(e, s);
  },
  ignoreSkipError: false,
  slowlyMs: slowlyMs,
  debounceTag: debounceTag,
  throttleTag: throttleTag,
  mutexTag: mutexTag,
);