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("Plugin '{0}' not found")]
27    PluginNotFound(String),
28
29    #[error("Invalid entry point format: {0}")]
30    InvalidEntryPoint(String),
31
32    #[error("IO error: {0}")]
33    Io(#[from] io::Error),
34}
35
36impl From<pyo3::PyErr> for BridgeError {
37    fn from(err: pyo3::PyErr) -> Self {
38        BridgeError::Python(format!("{}", err))
39    }
40}