Repository navigation
Expand file tree
/
Copy patherror.rs
More file actions
141 lines (124 loc) · 3.79 KB
/
Copy patherror.rs
File metadata and controls
141 lines (124 loc) · 3.79 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//! Common error types for `OpenShell`.
use miette::Diagnostic;
use thiserror::Error;
/// Result type alias using `OpenShell`'s error type.
pub type Result<T> = std::result::Result<T, Error>;
/// `OpenShell` error type.
#[derive(Debug, Error, Diagnostic)]
pub enum Error {
/// Configuration error.
#[error("configuration error: {message}")]
#[diagnostic(code(openshell::config))]
Config {
/// Error message.
message: String,
},
/// I/O error.
#[error("I/O error: {source}")]
#[diagnostic(code(openshell::io))]
Io {
/// Underlying I/O error.
#[from]
source: std::io::Error,
},
/// TLS error.
#[error("TLS error: {message}")]
#[diagnostic(code(openshell::tls))]
Tls {
/// Error message.
message: String,
},
/// gRPC transport error.
#[error("transport error: {message}")]
#[diagnostic(code(openshell::transport))]
Transport {
/// Error message.
message: String,
},
/// Execution error.
#[error("execution error: {message}")]
#[diagnostic(code(openshell::execution))]
Execution {
/// Error message.
message: String,
},
/// Process error.
#[error("process error: {message}")]
#[diagnostic(code(openshell::process))]
Process {
/// Error message.
message: String,
},
/// Timeout error.
#[error("operation timed out")]
#[diagnostic(code(openshell::timeout))]
Timeout,
}
impl Error {
/// Create a configuration error.
pub fn config(message: impl Into<String>) -> Self {
Self::Config {
message: message.into(),
}
}
/// Create a TLS error.
pub fn tls(message: impl Into<String>) -> Self {
Self::Tls {
message: message.into(),
}
}
/// Create a transport error.
pub fn transport(message: impl Into<String>) -> Self {
Self::Transport {
message: message.into(),
}
}
/// Create an execution error.
pub fn execution(message: impl Into<String>) -> Self {
Self::Execution {
message: message.into(),
}
}
/// Create a process error.
pub fn process(message: impl Into<String>) -> Self {
Self::Process {
message: message.into(),
}
}
}
/// Error type shared by all compute driver implementations.
///
/// Both the Podman and Kubernetes drivers map their backend-specific
/// errors into these variants before crossing crate boundaries.
#[derive(Debug, Error)]
pub enum ComputeDriverError {
/// The requested sandbox already exists.
#[error("sandbox already exists")]
AlreadyExists,
/// The request contains an invalid argument.
#[error("{0}")]
InvalidArgument(String),
/// A precondition for the operation was not met.
#[error("{0}")]
Precondition(String),
/// The backend may have accepted the operation, but its result could not be
/// determined. Callers must preserve durable intent for reconciliation.
#[error("{0}")]
Unavailable(String),
/// Generic error message.
#[error("{0}")]
Message(String),
}
impl From<ComputeDriverError> for tonic::Status {
fn from(err: ComputeDriverError) -> Self {
match err {
ComputeDriverError::AlreadyExists => Self::already_exists("sandbox already exists"),
ComputeDriverError::InvalidArgument(m) => Self::invalid_argument(m),
ComputeDriverError::Precondition(m) => Self::failed_precondition(m),
ComputeDriverError::Unavailable(m) => Self::unavailable(m),
ComputeDriverError::Message(m) => Self::internal(m),
}
}
}