Skip to main content

r2x_python/
errors.rs

1use std::io;
2use std::path::PathBuf;
3use thiserror::Error;
4
5/// Errors that can occur during Python bridge operations
6#[derive(Error, Debug)]
7pub enum BridgeError {
8    #[error("Python error: {0}")]
9    Python(String),
10
11    #[error("Failed to import module '{0}': {1}")]
12    Import(String, String),
13
14    #[error("Python venv not found or invalid at: {0}")]
15    VenvNotFound(PathBuf),
16
17    #[error("r2x-core is not installed in the Python environment")]
18    R2XCoreNotInstalled,
19
20    #[error("Failed to serialize/deserialize data: {0}")]
21    Serialization(String),
22
23    #[error("Failed to initialize Python interpreter: {0}")]
24    Initialization(String),
25
26    #[error("Python library not found: {0}")]
27    PythonLibraryNotFound(String),
28
29    #[error("Plugin '{0}' not found")]
30    PluginNotFound(String),
31
32    #[error("Invalid entry point format: {0}")]
33    InvalidEntryPoint(String),
34
35    #[error("IO error: {0}")]
36    Io(#[from] io::Error),
37}
38
39/// Generic conversion from PyErr to BridgeError.
40///
41/// NOTE: This conversion loses the Python traceback information!
42/// For user-facing errors where tracebacks are important (plugin failures,
43/// config instantiation, etc.), use `format_python_error()` or
44/// `format_exception_value()` from plugin_regular.rs instead.
45impl From<pyo3::PyErr> for BridgeError {
46    fn from(err: pyo3::PyErr) -> Self {
47        BridgeError::Python(format!("{}", err))
48    }
49}