visitErrors static method

void visitErrors(
  1. Object error,
  2. StackTrace stackTrace, {
  3. required void onFailure(
    1. Object error,
    2. StackTrace stackTrace
    ),
  4. void onCancelled(
    1. Cancelled cancelled,
    2. StackTrace stackTrace
    )?,
})

Walks error and hands each failure in it to onFailure and each cancellation to onCancelled, one at a time.

An outcome and a catch keep an error as it was thrown, and that can be a ParallelWaitError of [a, b].wait, holding failures and cancellations side by side: a check for error is Cancelled lets a cancellation inside it through. The hooks of an observer need no such walk: the job walks the error this way itself. A callback that throws ends the walk, and the error reaches the caller; when the caller is a hook of an observer, the job catches it and the zone gets it, except a Cancelled, which is dropped.

if (outcome case Failed(:final error, :final stackTrace)) {
  Job.visitErrors(error, stackTrace, onFailure: report);
}

Nothing is lost: what the walk cannot read goes to onFailure whole, with the stack trace of the error around it — a ParallelWaitError of a record longer than nine or of a shape it does not know, one whose list throws when read, one already being walked further up, and a branch that is not an AsyncError. The readable branches of a partly readable list are walked all the same. Each ParallelWaitError is walked at most once, by identity.

See Several failures in one error on the error rules page for the order of the walk.

Implementation

static void visitErrors(
  Object error,
  StackTrace stackTrace, {
  required void Function(Object error, StackTrace stackTrace) onFailure,
  void Function(Cancelled cancelled, StackTrace stackTrace)? onCancelled,
}) => _visitErrors(
  error,
  stackTrace,
  onFailure: onFailure,
  onCancelled: onCancelled,
);