1use bevy_ecs::prelude::{Entity, Resource};
19
20use backtrace::Backtrace;
21
22use anyhow::Error as Anyhow;
23
24use std::{borrow::Cow, sync::Arc};
25
26use crate::{Broken, Cancel, Disposal, OperationError};
27
28use thiserror::Error as ThisError;
29
30#[derive(Resource, Default, Clone, Debug)]
33pub struct UnhandledErrors {
34 pub setup: Vec<SetupFailure>,
35 pub cancellations: Vec<CancelFailure>,
36 pub operations: Vec<OperationError>,
37 pub disposals: Vec<DisposalFailure>,
38 pub stop_tasks: Vec<StopTaskFailure>,
39 pub broken: Vec<Broken>,
40 pub unused_targets: Vec<UnusedTargetDrop>,
41 pub connections: Vec<ConnectionFailure>,
42 pub duplicate_streams: Vec<DuplicateStream>,
43 pub flush_warnings: Vec<FlushWarning>,
44 pub miscellaneous: Vec<MiscellaneousFailure>,
45}
46
47impl UnhandledErrors {
48 pub fn is_empty(&self) -> bool {
49 self.setup.is_empty()
52 && self.cancellations.is_empty()
53 && self.operations.is_empty()
54 && self.disposals.is_empty()
55 && self.stop_tasks.is_empty()
56 && self.broken.is_empty()
57 && self.unused_targets.is_empty()
58 && self.connections.is_empty()
59 && self.duplicate_streams.is_empty()
60 && self.flush_warnings.is_empty()
61 && self.miscellaneous.is_empty()
62 }
63}
64
65#[derive(Clone, Debug)]
66pub struct SetupFailure {
67 pub broken_node: Entity,
68 pub error: OperationError,
69}
70
71#[derive(Clone, Debug)]
72pub struct CancelFailure {
73 pub error: OperationError,
75 pub cancel: Cancel,
77}
78
79impl CancelFailure {
80 pub fn new(error: OperationError, cancel: Cancel) -> Self {
81 Self { error, cancel }
82 }
83}
84
85#[derive(Clone, Debug)]
89pub struct DisposalFailure {
90 pub disposal: Disposal,
92 pub broken_node: Entity,
94 pub backtrace: Option<Backtrace>,
96}
97
98#[derive(Clone, Debug)]
100pub struct StopTaskFailure {
101 pub task: Entity,
103 pub backtrace: Option<Backtrace>,
105}
106
107#[derive(Clone, Debug)]
110pub struct UnusedTargetDrop {
111 pub unused_target: Entity,
113 pub dropped_series: Vec<Entity>,
115}
116
117#[derive(Clone, Debug)]
119pub struct ConnectionFailure {
120 pub original_target: Entity,
121 pub new_target: Entity,
122 pub backtrace: Backtrace,
123}
124
125#[derive(Clone, Debug)]
127pub struct MiscellaneousFailure {
128 pub error: Arc<Anyhow>,
129 pub backtrace: Option<Backtrace>,
130}
131
132#[derive(Clone, Debug)]
138pub struct DuplicateStream {
139 pub target: Entity,
141 pub type_name: &'static str,
143 pub stream_name: Option<Cow<'static, str>>,
146}
147
148#[derive(Clone, Debug, ThisError)]
149pub enum FlushWarning {
152 #[error("exceeded flush loop limit of {limit} with {reached}")]
153 ExceededFlushLoopLimit { limit: usize, reached: usize },
154 #[error(
155 "exceeded poll limit {limit} with {reached} while performing single-threaded execution"
156 )]
157 ExceededSingleThreadedPollLimit { limit: usize, reached: usize },
158 #[error("exceeded channel received limit of {limit} with {reached}")]
159 ExceededChannelReceivedLimit { limit: usize, reached: usize },
160}