1#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum Error {
11 #[error("transport I/O error: {0}")]
12 Transport(#[from] std::io::Error),
13
14 #[error("Incus API error (status {status_code}): {message}")]
15 Api { status_code: u16, message: String },
16
17 #[error("failed to (de)serialize a request or response body: {0}")]
18 Serialization(#[from] serde_json::Error),
19
20 #[error("response did not match any known Incus envelope shape: {0}")]
21 InvalidResponse(String),
22
23 #[error("response body exceeded the {limit}-byte cap")]
24 ResponseTooLarge { limit: usize },
25
26 #[error("operation is not cancellable (may_cancel is false)")]
27 NotCancellable,
28
29 #[error("operation {id} failed (status {status_code}): {}", err.as_deref().unwrap_or("no error message"))]
30 OperationFailed {
31 id: uuid::Uuid,
32 status_code: u16,
33 err: Option<String>,
34 },
35
36 #[error("precondition failed updating {resource} (stale ETag - re-fetch and retry)")]
37 PreconditionFailed { resource: String },
38
39 #[error("{resource} not found")]
40 NotFound { resource: String },
41
42 #[error("invalid request: {0}")]
43 InvalidRequest(String),
44
45 #[cfg(feature = "events")]
52 #[error("WebSocket protocol error on /1.0/events: {0}")]
53 WebSocketProtocol(String),
54
55 #[error("request timed out after {after:?} (request fully sent: {request_fully_sent})")]
64 Timeout {
65 after: std::time::Duration,
66 request_fully_sent: bool,
67 },
68}
69
70pub type Result<T> = std::result::Result<T, Error>;
71
72#[cfg(test)]
73#[path = "error_tests.rs"]
74mod tests;