-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror.rs
More file actions
71 lines (59 loc) · 1.6 KB
/
Copy patherror.rs
File metadata and controls
71 lines (59 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) 2026 vectorless developers
// SPDX-License-Identifier: Apache-2.0
//! Python exception types and error conversion.
use pyo3::exceptions::PyException;
use pyo3::prelude::*;
use ::vectorless::Error as RustError;
/// Python exception for vectorless errors.
#[pyclass(extends = PyException, subclass)]
pub struct VectorlessError {
message: String,
kind: String,
}
#[pymethods]
impl VectorlessError {
#[new]
fn new_py(message: String, kind: String) -> Self {
Self { message, kind }
}
#[getter]
fn message(&self) -> &str {
&self.message
}
#[getter]
fn kind(&self) -> &str {
&self.kind
}
fn __str__(&self) -> &str {
&self.message
}
fn __repr__(&self) -> String {
format!("VectorlessError('{}', kind='{}')", self.message, self.kind)
}
}
impl VectorlessError {
pub fn new(message: String, kind: &str) -> Self {
Self {
message,
kind: kind.to_string(),
}
}
}
impl From<VectorlessError> for PyErr {
fn from(err: VectorlessError) -> PyErr {
PyErr::new::<VectorlessError, _>((err.message, err.kind))
}
}
/// Convert vectorless errors to Python exceptions.
pub fn to_py_err(e: RustError) -> PyErr {
let message = e.to_string();
let kind = match &e {
RustError::DocumentNotFound(_) => "not_found",
RustError::Parse(_) => "parse",
RustError::Config(_) => "config",
RustError::Workspace(_) => "workspace",
RustError::Llm(_) => "llm",
_ => "unknown",
};
VectorlessError::new(message, kind).into()
}