Skip to main content

panes/
error.rs

1use crate::{NodeId, PanelId};
2
3/// Invalid constraint parameter.
4#[non_exhaustive]
5#[derive(Debug, thiserror::Error)]
6pub enum ConstraintError {
7    /// A constraint value is NaN.
8    #[error("{0} is NaN")]
9    IsNan(&'static str),
10    /// A constraint value is negative.
11    #[error("{0} is negative")]
12    IsNegative(&'static str),
13    /// A constraint value is infinite.
14    #[error("{0} is infinite")]
15    IsInfinite(&'static str),
16    /// Grow and fixed constraints are mutually exclusive.
17    #[error("grow and fixed are mutually exclusive")]
18    GrowFixedExclusive,
19    /// Minimum exceeds maximum.
20    #[error("min exceeds max")]
21    MinExceedsMax,
22    /// Resize delta must be finite.
23    #[error("delta must be finite")]
24    DeltaNotFinite,
25    /// Grid span overflows u16.
26    #[error("grid span {0} exceeds u16 max")]
27    GridSpanOverflow(usize),
28}
29
30/// Tree structure validation failure.
31#[non_exhaustive]
32#[derive(Debug, thiserror::Error)]
33pub enum TreeError {
34    /// Root is not set.
35    #[error("root is not set")]
36    RootNotSet,
37    /// Root was already set.
38    #[error("root already set")]
39    RootAlreadySet,
40    /// Root node missing from arena.
41    #[error("root node {0} missing from arena")]
42    RootMissing(NodeId),
43    /// Panel ID counter exhausted.
44    #[error("panel ID counter exhausted")]
45    PanelIdExhausted,
46    /// Node arena size exceeds u32 capacity.
47    #[error("node arena size exceeds u32 capacity")]
48    ArenaOverflow,
49    /// Node arena index exceeds u32 capacity.
50    #[error("node arena index exceeds u32 capacity")]
51    ArenaIndexOverflow,
52    /// A container references a missing child.
53    #[error("node {parent} references missing child {child}")]
54    MissingChild {
55        /// The parent node.
56        parent: NodeId,
57        /// The missing child node.
58        child: NodeId,
59    },
60    /// A node has no parent entry.
61    #[error("node {0} has no parent entry")]
62    NoParentEntry(NodeId),
63    /// A node's parent is missing from the arena.
64    #[error("parent {parent} of node {child} missing from arena")]
65    ParentMissing {
66        /// The missing parent node.
67        parent: NodeId,
68        /// The child node.
69        child: NodeId,
70    },
71    /// Parent-child mismatch between parent_map and children list.
72    #[error("parent_map says {parent} is parent of {child}, but children list disagrees")]
73    ParentChildMismatch {
74        /// The parent node.
75        parent: NodeId,
76        /// The child node.
77        child: NodeId,
78    },
79    /// At least one kind required.
80    #[error("at least one kind required")]
81    NoKinds,
82    /// Active index out of bounds.
83    #[error("active index {active} out of bounds for {len} panels")]
84    ActiveOutOfBounds {
85        /// The active index.
86        active: usize,
87        /// The number of panels.
88        len: usize,
89    },
90    /// Dashboard requires at least one card.
91    #[error("dashboard requires at least one card")]
92    DashboardNoCards,
93    /// Dashboard columns must be at least 1.
94    #[error("dashboard columns must be at least 1")]
95    DashboardNoColumns,
96    /// Window size must be at least 1.
97    #[error("window size must be at least 1")]
98    WindowSizeZero,
99    /// Tree empty after rebuild.
100    #[error("empty after rebuild")]
101    EmptyAfterRebuild,
102    /// No root node.
103    #[error("no root")]
104    NoRoot,
105    /// Column count must be at least 1.
106    #[error("column count must be at least 1")]
107    ColumnsCountZero,
108    /// Wrapped error from Taffy or other dynamic source.
109    #[error("{0}")]
110    Dynamic(Box<str>),
111}
112
113/// Invalid viewport dimensions.
114#[non_exhaustive]
115#[derive(Debug, thiserror::Error)]
116pub enum ViewportError {
117    /// Dimension is NaN.
118    #[error("dimension is NaN")]
119    IsNan,
120    /// Dimension is negative.
121    #[error("dimension is negative")]
122    IsNegative,
123    /// Dimension is infinite.
124    #[error("dimension is infinite")]
125    IsInfinite,
126    /// No saved constraints for a panel.
127    #[error("no saved constraints for panel {0}")]
128    NoSavedConstraints(PanelId),
129}
130
131/// A mutation is not supported or invalid for the current state.
132#[non_exhaustive]
133#[derive(Debug, thiserror::Error)]
134pub enum MutationError {
135    /// No strategy set on the runtime.
136    #[error("no strategy set")]
137    NoStrategy,
138    /// No panel is focused.
139    #[error("no focused panel")]
140    NoFocusedPanel,
141    /// Focused panel has no parent.
142    #[error("focused panel has no parent")]
143    FocusedNoParent,
144    /// Parent is not a container node.
145    #[error("parent is not a container")]
146    ParentNotContainer,
147    /// Panel has no parent.
148    #[error("panel has no parent")]
149    PanelNoParent,
150    /// Panel is the only child.
151    #[error("panel is the only child")]
152    OnlyChild,
153    /// resize_boundary requires all siblings to be panels.
154    #[error("resize_boundary requires all siblings to be panels")]
155    SiblingsNotPanels,
156    /// resize_boundary requires all siblings to use grow constraints.
157    #[error("resize_boundary requires all siblings to use grow constraints")]
158    SiblingsNotGrow,
159    /// No collapsed slots to uncollapse.
160    #[error("no collapsed slots to uncollapse")]
161    NoCollapsedSlots,
162    /// Slot has no saved constraints.
163    #[error("slot has no saved constraints")]
164    SlotNoSavedConstraints,
165    /// Move not supported for this layout.
166    #[error("move not supported for this layout")]
167    MoveNotSupported,
168}
169
170/// Errors arising from layout operations on panels and nodes.
171#[non_exhaustive]
172#[derive(Debug, thiserror::Error)]
173pub enum PaneError {
174    /// A panel ID does not exist in the tree.
175    #[error("panel not found: {0}")]
176    PanelNotFound(PanelId),
177
178    /// A constraint value is invalid (NaN, negative, mutually exclusive).
179    #[error("invalid constraint: {0}")]
180    InvalidConstraint(ConstraintError),
181
182    /// A node ID does not exist in the arena.
183    #[error("node not found: {0}")]
184    NodeNotFound(NodeId),
185
186    /// The tree structure is invalid or incomplete.
187    #[error("tree validation failed: {0}")]
188    InvalidTree(TreeError),
189
190    /// Viewport dimensions are invalid (NaN, negative, infinite).
191    #[error("invalid viewport: {0}")]
192    InvalidViewport(ViewportError),
193
194    /// A mutation is not supported for the current strategy.
195    #[error("invalid mutation: {0}")]
196    InvalidMutation(MutationError),
197
198    /// A sequence index is out of bounds.
199    #[error("sequence index {0} out of bounds for length {1}")]
200    SequenceOutOfBounds(usize, usize),
201}