laravel_nestedset/
error.rs1use std::error::Error;
4use std::fmt;
5
6#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum NestedSetError {
10 NodeNotFound {
12 model: &'static str,
14 key: String,
16 },
17 MoveIntoOwnSubtree {
19 model: &'static str,
21 key: String,
23 target: String,
25 },
26 OutsideScope {
29 model: &'static str,
31 },
32 DuplicateKey {
34 model: &'static str,
36 key: String,
38 },
39 ScopeMismatch {
41 model: &'static str,
43 key: String,
45 target: String,
47 },
48}
49
50impl fmt::Display for NestedSetError {
51 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
52 match self {
53 Self::NodeNotFound { model, key } => {
54 write!(f, "The `{model}` node with the key `{key}` no longer exists.")
55 }
56 Self::MoveIntoOwnSubtree { model, key, target } => write!(
57 f,
58 "The `{model}` node `{key}` can't move next to `{target}`, which is the node itself or below it."
59 ),
60 Self::OutsideScope { model } => write!(
61 f,
62 "The new `{model}` root isn't in the scope it was created in: build the scope from the same columns as `{model}::scope`."
63 ),
64 Self::DuplicateKey { model, key } => {
65 write!(f, "The arrangement lists the `{model}` node `{key}` more than once.")
66 }
67 Self::ScopeMismatch { model, key, target } => write!(
68 f,
69 "The `{model}` node `{key}` can't move next to `{target}`, which is in another tree."
70 ),
71 }
72 }
73}
74
75impl Error for NestedSetError {}