dynpatch_core/
error.rs

1//! Error types for dynpatch-core
2
3use dynpatch_interface::PatchError;
4use std::path::PathBuf;
5use thiserror::Error;
6
7/// Result type for dynpatch operations
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Errors that can occur in the dynpatch runtime
11#[derive(Error, Debug)]
12pub enum Error {
13    #[error("Failed to load library: {path}")]
14    LibraryLoadError {
15        path: PathBuf,
16        #[source]
17        source: libloading::Error,
18    },
19
20    #[error("Symbol not found: {symbol}")]
21    SymbolNotFound {
22        symbol: String,
23    },
24
25    #[error("ABI validation failed: {0}")]
26    AbiValidationFailed(String),
27
28    #[error("Version mismatch: expected {expected}, found {found}")]
29    VersionMismatch {
30        expected: String,
31        found: String,
32    },
33
34    #[error("Type layout mismatch for {type_name}: expected size={expected_size} align={expected_align}, found size={found_size} align={found_align}")]
35    TypeLayoutMismatch {
36        type_name: String,
37        expected_size: usize,
38        expected_align: usize,
39        found_size: usize,
40        found_align: usize,
41    },
42
43    #[error("Patch initialization failed (code {code}): {message}")]
44    InitializationFailed {
45        code: i32,
46        message: String,
47    },
48
49    #[error("No patch loaded")]
50    NoPatchLoaded,
51
52    #[error("No previous patch to rollback to")]
53    NoPreviousPatch,
54
55    #[error("Invalid patch format: {0}")]
56    InvalidPatchFormat(String),
57
58    #[error("Patch interface error: {0}")]
59    PatchInterface(#[from] PatchError),
60
61    #[error("IO error: {0}")]
62    Io(#[from] std::io::Error),
63
64    #[error("Serialization error: {0}")]
65    Serialization(String),
66
67    #[error("Other error: {0}")]
68    Other(String),
69}
70
71impl From<String> for Error {
72    fn from(s: String) -> Self {
73        Error::Other(s)
74    }
75}
76
77impl From<&str> for Error {
78    fn from(s: &str) -> Self {
79        Error::Other(s.to_string())
80    }
81}