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("Invalid artifact bundle: {0}")]
36    InvalidArtifact(String),
37
38    #[error("Plugin stream error: {0}")]
39    Stream(String),
40
41    #[error("Artifact-mode invocation is unsupported: {0}")]
42    UnsupportedArtifactMode(String),
43
44    #[error("IO error: {0}")]
45    Io(#[from] io::Error),
46}
47
48/// Generic conversion from PyErr to BridgeError.
49///
50/// NOTE: This conversion loses the Python traceback information!
51/// For user-facing errors where tracebacks are important (plugin failures,
52/// config instantiation, etc.), use `format_python_error()` or
53/// `format_exception_value()` from plugin_regular.rs instead.
54impl From<pyo3::PyErr> for BridgeError {
55    fn from(err: pyo3::PyErr) -> Self {
56        BridgeError::Python(format!("{}", err))
57    }
58}