1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2025 Umberto Gotti <umberto.gotti@umbertogotti.dev>
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
/// Extension trait providing the `on_error` operator for streams.
///
/// This trait allows any stream of `StreamItem<T>` to handle errors
/// with a custom handler function.
///
/// Use [`OnErrorExt::on_error`] to use this operator.
///
/// # Behavior
///
/// - The handler receives a reference to each error and returns:
/// - `true` to consume the error (remove from stream)
/// - `false` to propagate the error downstream
///
/// Use `on_error` for side effects (logging) or error recovery (suppression).
///
/// # Examples
///
/// ## Basic Error Consumption
///
/// ```rust
/// use fluxion_stream::{OnErrorExt, IntoFluxionStream};
/// use fluxion_core::{FluxionError, StreamItem};
/// use fluxion_test_utils::Sequenced;
/// use futures::StreamExt;
///
/// # async fn example() {
/// let (tx, rx) = async_channel::unbounded();
/// let stream = rx.into_fluxion_stream();
///
/// let mut stream = stream
/// .on_error(|err| {
/// eprintln!("Error: {}", err);
/// true // Consume all errors
/// });
///
/// tx.try_send(Sequenced::new(1)).unwrap();
/// assert_eq!(stream.next().await.unwrap().unwrap().into_inner(), 1);
/// # }
/// ```
///
/// # See Also
///
/// - [`OnErrorExt::on_error`]
pub use OnErrorExt;
pub use OnErrorExt;