Skip to main content

OnError

Type Alias OnError 

pub type OnError<'a> = &'a mut dyn FnMut(&mut OnErrorContext<'_>) -> bool;
Expand description

The on_error callback type: return true to resume, false to re-raise.

The callback owns termination. Recovery is deliberately unbounded: the loop consults this callback on every iteration and stops the moment it returns false, but it imposes no limit of its own, so a callback that always returns true can loop forever. That is a real risk only when the error cannot be recovered past — see Lark::parse_custom, where a crate::TokenSource that keeps reporting the same failure never advances. Over ordinary text every iteration consumes a character, so an always-true callback terminates in text.len() iterations.

The bound is absent by design rather than by omission: every candidate had to threshold a quantity the façade cannot measure (a custom source owns its own position), and each one refused legitimate recoveries. A callback that needs a limit should count its own calls, or key off a deadline.