tokio_zookeeper/
error.rs

1use snafu::Snafu;
2
3/// Errors returned by tokio-zookeeper (rather than by the ZooKeeper server)
4// Largely a copy of snafu::Whatever, adapted to provide Send+Sync
5#[derive(Debug, Snafu)]
6#[snafu(whatever, display("{message}"))]
7pub struct Error {
8    #[snafu(source(from(Box<dyn std::error::Error + Send + Sync>, Some)))]
9    source: Option<Box<dyn std::error::Error + Send + Sync>>,
10    message: String,
11}
12
13/// Errors that may cause a delete request to fail.
14#[derive(Clone, Copy, PartialEq, Eq, Debug, Snafu)]
15#[snafu(module)]
16pub enum Delete {
17    /// No node exists with the given `path`.
18    #[snafu(display("target node does not exist"))]
19    NoNode,
20
21    /// The target node has a different version than was specified by the call to delete.
22    #[snafu(display("target node has different version than expected ({expected})"))]
23    BadVersion {
24        /// The expected node version.
25        expected: i32,
26    },
27
28    /// The target node has child nodes, and therefore cannot be deleted.
29    #[snafu(display("target node has children, and cannot be deleted"))]
30    NotEmpty,
31}
32
33/// Errors that may cause a `set_data` request to fail.
34#[derive(Clone, Copy, PartialEq, Eq, Debug, Snafu)]
35#[snafu(module)]
36pub enum SetData {
37    /// No node exists with the given `path`.
38    #[snafu(display("target node does not exist"))]
39    NoNode,
40
41    /// The target node has a different version than was specified by the call to `set_data`.
42    #[snafu(display("target node has different version than expected ({expected})"))]
43    BadVersion {
44        /// The expected node version.
45        expected: i32,
46    },
47
48    /// The target node's permission does not accept data modification or requires different
49    /// authentication to be altered.
50    #[snafu(display("insuficient authentication"))]
51    NoAuth,
52}
53
54/// Errors that may cause a create request to fail.
55#[derive(Clone, Copy, PartialEq, Eq, Debug, Snafu)]
56#[snafu(module)]
57pub enum Create {
58    /// A node with the given `path` already exists.
59    #[snafu(display("target node already exists"))]
60    NodeExists,
61
62    /// The parent node of the given `path` does not exist.
63    #[snafu(display("parent node of target does not exist"))]
64    NoNode,
65
66    /// The parent node of the given `path` is ephemeral, and cannot have children.
67    #[snafu(display("parent node is ephemeral, and cannot have children"))]
68    NoChildrenForEphemerals,
69
70    /// The given ACL is invalid.
71    #[snafu(display("the given ACL is invalid"))]
72    InvalidAcl,
73}
74
75/// Errors that may cause a `get_acl` request to fail.
76#[derive(Clone, Copy, PartialEq, Eq, Debug, Snafu)]
77#[snafu(module)]
78pub enum GetAcl {
79    /// No node exists with the given `path`.
80    #[snafu(display("target node does not exist"))]
81    NoNode,
82}
83
84/// Errors that may cause a `set_acl` request to fail.
85#[derive(Clone, Copy, PartialEq, Eq, Debug, Snafu)]
86#[snafu(module)]
87pub enum SetAcl {
88    /// No node exists with the given `path`.
89    #[snafu(display("target node does not exist"))]
90    NoNode,
91
92    /// The target node has a different version than was specified by the call to `set_acl`.
93    #[snafu(display("target node has different version than expected ({expected})"))]
94    BadVersion {
95        /// The expected node version.
96        expected: i32,
97    },
98
99    /// The given ACL is invalid.
100    #[snafu(display("the given ACL is invalid"))]
101    InvalidAcl,
102
103    /// The target node's permission does not accept acl modification or requires different
104    /// authentication to be altered.
105    #[snafu(display("insufficient authentication"))]
106    NoAuth,
107}
108
109/// Errors that may cause a `check` request to fail.
110#[derive(Clone, Copy, PartialEq, Eq, Debug, Snafu)]
111#[snafu(module)]
112pub enum Check {
113    /// No node exists with the given `path`.
114    #[snafu(display("target node does not exist"))]
115    NoNode,
116
117    /// The target node has a different version than was specified by the call to `check`.
118    #[snafu(display("target node has different version than expected ({expected})"))]
119    BadVersion {
120        /// The expected node version.
121        expected: i32,
122    },
123}
124
125/// The result of a failed `multi` request.
126#[derive(Clone, Copy, PartialEq, Eq, Debug, Snafu)]
127pub enum Multi {
128    /// A failed `delete` request.
129    #[snafu(display("delete failed"), context(false))]
130    Delete {
131        /// The source error.
132        source: Delete,
133    },
134
135    /// A failed `set_data` request.
136    #[snafu(display("set_data failed"), context(false))]
137    SetData {
138        /// The source error.
139        source: SetData,
140    },
141
142    /// A failed `create` request.
143    #[snafu(display("create failed"), context(false))]
144    Create {
145        /// The source error.
146        source: Create,
147    },
148
149    /// A failed `check` request.
150    #[snafu(display("check failed"), context(false))]
151    Check {
152        /// The source error.
153        source: Check,
154    },
155
156    /// The request would have succeeded, but a later request in the `multi`
157    /// batch failed and caused this request to get rolled back.
158    #[snafu(display("request rolled back due to later failed request"))]
159    RolledBack,
160
161    /// The request was skipped because an earlier request in the `multi` batch
162    /// failed. It is unknown whether this request would have succeeded.
163    #[snafu(display("request failed due to earlier failed request"))]
164    Skipped,
165}