Skip to main content

error_chain_with

Function error_chain_with 

pub fn error_chain_with<'a, F>(
    error: &'a (dyn Error + 'static),
    max_depth: usize,
    next_source: F,
) -> impl Iterator<Item = &'a (dyn Error + 'static)>
where F: FnMut(&'a (dyn Error + 'static)) -> Option<&'a (dyn Error + 'static)>,
Expand description

Iterate over an error and custom successors, visiting at most max_depth errors.

The supplied error is included in the limit. The next_source callback selects one successor per error, replacing Error::source traversal. Return None to end the chain, or explicitly call Error::source in the callback when it should provide the fallback successor.

The callback runs only when another item is requested within the limit. It is never called for a zero or one-item limit, or after the chain ends. The iterator does not allocate or deduplicate errors, and the limit also bounds cycles introduced by the callback.