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
//! The error utilities.
/// An framework error.
#[derive(Debug)]
pub enum Error {
/// A custom error.
///
/// Generally refers to errors generated by other crates.
Custom(Box<dyn std::error::Error>),
/// The operation is invalid before component created.
TreeNotCreated,
/// A wrong node tree is visited.
///
/// Generally refers to some bad operation had being done directly in the node tree.
TreeNodeTypeWrong,
/// The backend tree node has been released.
///
/// Generally refers to some bad operation had being done directly in the node tree.
TreeNodeReleased,
/// A list update failed due to wrong changes list.
///
/// Generally refers to some bad operation had being done directly in the node tree.
ListChangeWrong,
/// A recursive update is detected.
///
/// An element cannot be updated while it is still in another update process.
/// This will not happen while calling async update methods like `ComponentRc::task` or `ComponentRc::update` .
/// Generally refers to some manually update process being incorrectly triggered.
RecursiveUpdate,
/// The backend context has already entered.
AlreadyEntered,
/// A general backend failure.
BackendError {
/// The message from backend.
msg: String,
/// The detailed backend error object.
err: Option<Box<dyn std::error::Error>>,
},
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Custom(err) => {
write!(f, "{}", err)?;
}
Error::TreeNotCreated => {
write!(f, "Component template has not been initialized")?;
}
Error::TreeNodeTypeWrong => {
write!(f, "The node type in backend element tree is incorrect")?;
}
Error::TreeNodeReleased => {
write!(f, "The node in backend element tree has been released")?;
}
Error::ListChangeWrong => {
write!(f, "The list change is incorrect")?;
}
Error::RecursiveUpdate => {
write!(f, "A recursive update is detected")?;
}
Error::AlreadyEntered => {
write!(f, "The backend context is already entered")?;
}
Error::BackendError { msg, err } => {
if let Some(err) = err {
write!(f, "{}: {}", msg, err.to_string())?;
} else {
write!(f, "{}", msg)?;
}
}
}
Ok(())
}
}
impl std::error::Error for Error {}