codeprism_lang_python/
error.rs1use std::path::PathBuf;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
8pub enum Error {
9 #[error("Failed to parse {file}: {message}")]
11 ParseError { file: PathBuf, message: String },
12
13 #[error("Tree-sitter error in {file}: {message}")]
15 TreeSitterError { file: PathBuf, message: String },
16
17 #[error("AST mapping error in {file}: {message}")]
19 AstMappingError { file: PathBuf, message: String },
20
21 #[error("IO error: {0}")]
23 Io(#[from] std::io::Error),
24
25 #[error("JSON error: {0}")]
27 Json(#[from] serde_json::Error),
28
29 #[error("Python parser error: {0}")]
31 Generic(String),
32}
33
34impl Error {
35 pub fn parse(file: &std::path::Path, message: &str) -> Self {
37 Self::ParseError {
38 file: file.to_path_buf(),
39 message: message.to_string(),
40 }
41 }
42
43 pub fn tree_sitter(file: &std::path::Path, message: &str) -> Self {
45 Self::TreeSitterError {
46 file: file.to_path_buf(),
47 message: message.to_string(),
48 }
49 }
50
51 pub fn ast_mapping(file: &std::path::Path, message: &str) -> Self {
53 Self::AstMappingError {
54 file: file.to_path_buf(),
55 message: message.to_string(),
56 }
57 }
58
59 pub fn generic(message: &str) -> Self {
61 Self::Generic(message.to_string())
62 }
63}
64
65pub type Result<T> = std::result::Result<T, Error>;