informationCollector property

InformationCollector? informationCollector

A callback which will provide information that could help with debugging the problem.

Information collector callbacks can be expensive, so the generated information should be cached by the caller, rather than the callback being called multiple times.

The callback is expected to return an iterable of DiagnosticsNode objects, typically implemented using sync* and yield.

In this example, the information collector returns two pieces of information, one broadly-applicable statement regarding how the error happened, and one giving a specific piece of information that may be useful in some cases but may also be irrelevant most of the time (an argument to the method).
void climbElevator(int pid) {
  try {
    // ...
  } catch (error, stack) {
      exception: error,
      stack: stack,
      informationCollector: () => <DiagnosticsNode>[
        ErrorDescription('This happened while climbing the space elevator.'),
        ErrorHint('The process ID is: $pid'),

The following classes may be of particular use:

  • ErrorDescription, for information that is broadly applicable to the situation being described.
  • ErrorHint, for specific information that may not always be applicable but can be helpful in certain situations.
  • DiagnosticsStackTrace, for reporting stack traces.
  • ErrorSpacer, for adding spaces (a blank line) between other items.

For objects that implement Diagnosticable one may consider providing additional information by yielding the output of the object's Diagnosticable.toDiagnosticsNode method.


final InformationCollector? informationCollector;