qemu_plugin/error/
mod.rs

1//! Errors that can occur in the qemu-plugin crate
2
3#[derive(thiserror::Error, Debug)]
4/// An error from the qemu-plugin crate
5pub enum Error {
6    #[error("Missing key for argument {argument}")]
7    /// Error when an argument is missing a key
8    MissingArgKey {
9        /// The argument string a key is missing for
10        argument: String,
11    },
12    #[error("Missing value for argument {argument}")]
13    /// Error when an argument is missing a value
14    MissingArgValue {
15        /// The argument string a value is missing for
16        argument: String,
17    },
18    #[error("Invalid boolean value {name} ({val})")]
19    /// Error when a boolean argument is invalid
20    InvalidBool {
21        /// The name of the key-value argument pair which does not correctly parse as boolean
22        name: String,
23        /// The value of the key-value argument pair which does not correctly parse as boolean
24        val: String,
25    },
26    #[error(
27        "Setting the QEMU plugin uninstall callback was attempted concurrently and this attempt failed."
28    )]
29    /// Error when the QEMU plugin uninstall callback is set concurrently
30    ConcurrentPluginUninstallCallbackSet,
31    #[error(
32        "Setting the QEMU plugin reset callback was attempted concurrently and this attempt failed."
33    )]
34    /// Error when the QEMU plugin reset callback is set concurrently
35    ConcurrentPluginResetCallbackSet,
36    #[error("Invalid state for plugin reset callback")]
37    /// Error when the plugin reset callback is in an invalid state
38    PluginResetCallbackState,
39    #[error("Invalid instruction index {index} for translation block of size {size}")]
40    /// Error when an instruction index is invalid
41    InvalidInstructionIndex {
42        /// The index into the translation block that is invalid
43        index: usize,
44        /// The size of the translation block
45        size: usize,
46    },
47    #[error("No disassembly string available for instruction")]
48    /// Error when no disassembly string is available for an instruction (i.e. NULL string
49    NoDisassemblyString,
50    #[error("Invalid size {size} for read of register {name}")]
51    /// Error when the size of a register read is invalid
52    InvalidRegisterReadSize {
53        /// The register name
54        name: String,
55        /// The size of the attempted read
56        size: usize,
57    },
58    #[error("Error while reading register {name}")]
59    /// Error when reading a register fails
60    RegisterReadError {
61        /// The register name
62        name: String,
63    },
64    #[error("Error while writing register {name}")]
65    /// Error when writing a register fails
66    RegisterWriteError {
67        /// The register name
68        name: String,
69    },
70    #[cfg(not(any(
71        feature = "plugin-api-v0",
72        feature = "plugin-api-v1",
73        feature = "plugin-api-v2",
74        feature = "plugin-api-v3"
75    )))]
76    #[error("Error while reading {len} bytes from virtual address {addr:#x}")]
77    /// Error when reading memory from a virtual address fails
78    VaddrReadError {
79        /// The address read from
80        addr: u64,
81        /// The number of bytes read
82        len: u32,
83    },
84    #[cfg(not(any(
85        feature = "plugin-api-v0",
86        feature = "plugin-api-v1",
87        feature = "plugin-api-v2",
88        feature = "plugin-api-v3",
89        feature = "plugin-api-v4"
90    )))]
91    #[error("Error while writing {len} bytes to virtual address {addr:#x}")]
92    /// Error when writing memory from a virtual address fails
93    VaddrWriteError {
94        /// The address written to
95        addr: u64,
96        /// The number of bytes written
97        len: u32,
98    },
99    #[cfg(not(any(
100        feature = "plugin-api-v0",
101        feature = "plugin-api-v1",
102        feature = "plugin-api-v2",
103        feature = "plugin-api-v3",
104        feature = "plugin-api-v4"
105    )))]
106    #[error("Error while reading {len} bytes from hardware address {addr:#x}: {result}")]
107    /// Error when reading memory from a hardware address fails
108    HwaddrReadError {
109        /// The address read from
110        addr: u64,
111        /// The number of bytes read
112        len: u32,
113        /// The operation result
114        result: crate::HwaddrOperationResult,
115    },
116    #[cfg(not(any(
117        feature = "plugin-api-v0",
118        feature = "plugin-api-v1",
119        feature = "plugin-api-v2",
120        feature = "plugin-api-v3",
121        feature = "plugin-api-v4"
122    )))]
123    #[error("Error while writing {len} bytes to hardware address {addr:#x}: {result}")]
124    /// Error when writing memory from a hardware address fails
125    HwaddrWriteError {
126        /// The address written to
127        addr: u64,
128        /// The number of bytes written
129        len: u32,
130        /// The operation result
131        result: crate::HwaddrOperationResult,
132    },
133    #[cfg(not(any(
134        feature = "plugin-api-v0",
135        feature = "plugin-api-v1",
136        feature = "plugin-api-v2",
137        feature = "plugin-api-v3",
138        feature = "plugin-api-v4"
139    )))]
140    #[error("Error while translating virtual address {vaddr:#x} to hardware address")]
141    /// Error when translating a virtual address to a hardware address fails
142    VaddrTranslateError {
143        /// The virtual address that failed to translate
144        vaddr: u64,
145    },
146    #[error("Error while setting global plugin instance")]
147    /// Error when setting the global plugin instance fails
148    PluginInstanceSetError,
149    #[error(transparent)]
150    /// A transparently wrapped `std::str::Utf8Error`
151    StdUtf8Error(#[from] std::str::Utf8Error),
152    #[error(transparent)]
153    /// A transparently wrapped `core::convert::Infallible`
154    Infallible(#[from] core::convert::Infallible),
155    #[error(transparent)]
156    /// A transparently wrapped `std::alloc::LayoutError`
157    LayoutError(#[from] std::alloc::LayoutError),
158    #[error(transparent)]
159    /// A transparently wrapped `std::array::TryFromSliceError`
160    TryFromSliceError(#[from] std::array::TryFromSliceError),
161    #[error(transparent)]
162    /// A transparently wrapped `std::cell::BorrowError`
163    BorrowError(#[from] std::cell::BorrowError),
164    #[error(transparent)]
165    /// A transparently wrapped `std::cell::BorrowMutError`
166    BorrowMutError(#[from] std::cell::BorrowMutError),
167    #[error(transparent)]
168    /// A transparently wrapped `std::char::CharTryFromError`
169    CharTryFromError(#[from] std::char::CharTryFromError),
170    #[error(transparent)]
171    /// A transparently wrapped `std::char::DecodeUtf16Error`
172    DecodeUtf16Error(#[from] std::char::DecodeUtf16Error),
173    #[error(transparent)]
174    /// A transparently wrapped `std::char::ParseCharError`
175    ParseCharError(#[from] std::char::ParseCharError),
176    #[error(transparent)]
177    /// A transparently wrapped `std::char::TryFromCharError`
178    TryFromCharError(#[from] std::char::TryFromCharError),
179    #[error(transparent)]
180    /// A transparently wrapped `std::collections::TryReserveError`
181    TryReserveError(#[from] std::collections::TryReserveError),
182    #[error(transparent)]
183    /// A transparently wrapped `std::env::JoinPathsError`
184    JoinPathsError(#[from] std::env::JoinPathsError),
185    #[error(transparent)]
186    /// A transparently wrapped `std::env::VarError`
187    VarError(#[from] std::env::VarError),
188    #[error(transparent)]
189    /// A transparently wrapped `std::ffi::FromBytesUntilNulError`
190    FromBytesUntilNulError(#[from] std::ffi::FromBytesUntilNulError),
191    #[error(transparent)]
192    /// A transparently wrapped `std::ffi::FromBytesWithNulError`
193    FromBytesWithNulError(#[from] std::ffi::FromBytesWithNulError),
194    #[error(transparent)]
195    /// A transparently wrapped `std::ffi::FromVecWithNulError`
196    FromVecWithNulError(#[from] std::ffi::FromVecWithNulError),
197    #[error(transparent)]
198    /// A transparently wrapped `std::ffi::IntoStringError`
199    IntoStringError(#[from] std::ffi::IntoStringError),
200    #[error(transparent)]
201    /// A transparently wrapped `std::ffi::NulError`
202    NulError(#[from] std::ffi::NulError),
203    #[error(transparent)]
204    /// A transparently wrapped `std::fmt::Error`
205    FmtError(#[from] std::fmt::Error),
206    #[error(transparent)]
207    /// A transparently wrapped `std::fs::TryLockError`
208    FsTryLockError(#[from] std::fs::TryLockError),
209    #[error(transparent)]
210    /// A transparently wrapped `std::io::Error`
211    IoError(#[from] std::io::Error),
212    #[error(transparent)]
213    /// A transparently wrapped `std::net::AddrParseError`
214    AddrParseError(#[from] std::net::AddrParseError),
215    #[error(transparent)]
216    /// A transparently wrapped `std::num::ParseFloatError`
217    ParseFloatError(#[from] std::num::ParseFloatError),
218    #[error(transparent)]
219    /// A transparently wrapped `std::num::ParseIntError`
220    ParseIntError(#[from] std::num::ParseIntError),
221    #[error(transparent)]
222    /// A transparently wrapped `std::num::TryFromIntError`
223    TryFromIntError(#[from] std::num::TryFromIntError),
224    #[error(transparent)]
225    /// A transparently wrapped `std::path::StripPrefixError`
226    StripPrefixError(#[from] std::path::StripPrefixError),
227    #[error(transparent)]
228    /// A transparently wrapped `std::str::ParseBoolError`
229    ParseBoolError(#[from] std::str::ParseBoolError),
230    #[error(transparent)]
231    /// A transparently wrapped `std::string::FromUtf8Error`
232    FromUtf8Error(#[from] std::string::FromUtf8Error),
233    #[error(transparent)]
234    /// A transparently wrapped `std::string::FromUtf16Error`
235    FromUtf16Error(#[from] std::string::FromUtf16Error),
236    #[error(transparent)]
237    /// A transparently wrapped `std::sync::mpsc::RecvError`
238    RecvError(#[from] std::sync::mpsc::RecvError),
239    #[error(transparent)]
240    /// A transparently wrapped `std::sync::mpsc::RecvTimeoutError`
241    RecvTimeoutError(#[from] std::sync::mpsc::RecvTimeoutError),
242    #[error(transparent)]
243    /// A transparently wrapped `std::sync::mpsc::TryRecvError`
244    TryRecvError(#[from] std::sync::mpsc::TryRecvError),
245    #[error(transparent)]
246    /// A transparently wrapped `std::thread::AccessError`
247    AccessError(#[from] std::thread::AccessError),
248    #[error(transparent)]
249    /// A transparently wrapped `std::time::SystemTimeError`
250    SystemTimeError(#[from] std::time::SystemTimeError),
251    #[error(transparent)]
252    /// A transparently wrapped `std::time::TryFromFloatSecsError`
253    TryFromFloatSecsError(#[from] std::time::TryFromFloatSecsError),
254    #[cfg(windows)]
255    #[error(transparent)]
256    /// A transparently wrapped `std::os::windows::io::InvalidHandleError`
257    InvalidHandleError(#[from] std::os::windows::io::InvalidHandleError),
258    #[cfg(windows)]
259    #[error(transparent)]
260    /// A transparently wrapped `std::os::windows::io::NullHandleError`
261    NullHandleError(#[from] std::os::windows::io::NullHandleError),
262    #[cfg(feature = "anyhow")]
263    #[error(transparent)]
264    /// A transparently wrapped `anyhow::Error`
265    AnyhowError(#[from] anyhow::Error),
266    #[error(transparent)]
267    /// A transparently wrapped `Box<dyn std::error::Error>`
268    BoxedError(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
269}
270
271#[allow(dead_code)]
272/// Assert that Error is Send + Sync
273fn _assert_error_is_send_sync() {
274    fn assert_send_sync<T: Send + Sync>() {}
275    assert_send_sync::<Error>();
276}
277
278/// Result type for the qemu-plugin crate
279pub type Result<T> = std::result::Result<T, Error>;