codegraph_python/
error.rs1use std::io;
2use std::path::PathBuf;
3use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, ParseError>;
7
8#[derive(Error, Debug)]
10pub enum ParseError {
11 #[error("Failed to read file {path}: {source}")]
13 IoError { path: PathBuf, source: io::Error },
14
15 #[error(
17 "File {path} exceeds maximum size limit of {max_size} bytes (actual: {actual_size} bytes)"
18 )]
19 FileTooLarge {
20 path: PathBuf,
21 max_size: usize,
22 actual_size: usize,
23 },
24
25 #[error("Syntax error in {file} at line {line}, column {column}: {message}")]
27 SyntaxError {
28 file: String,
29 line: usize,
30 column: usize,
31 message: String,
32 },
33
34 #[error("Graph operation failed: {0}")]
36 GraphError(String),
37
38 #[error("Invalid configuration: {0}")]
40 InvalidConfig(String),
41
42 #[error("Unsupported Python feature in {file}: {feature}")]
44 UnsupportedFeature { file: String, feature: String },
45}
46
47impl ParseError {
48 pub fn io_error(path: impl Into<PathBuf>, source: io::Error) -> Self {
50 ParseError::IoError {
51 path: path.into(),
52 source,
53 }
54 }
55
56 pub fn file_too_large(path: impl Into<PathBuf>, max_size: usize, actual_size: usize) -> Self {
58 ParseError::FileTooLarge {
59 path: path.into(),
60 max_size,
61 actual_size,
62 }
63 }
64
65 pub fn syntax_error(
67 file: impl Into<String>,
68 line: usize,
69 column: usize,
70 message: impl Into<String>,
71 ) -> Self {
72 ParseError::SyntaxError {
73 file: file.into(),
74 line,
75 column,
76 message: message.into(),
77 }
78 }
79
80 pub fn graph_error(message: impl Into<String>) -> Self {
82 ParseError::GraphError(message.into())
83 }
84
85 pub fn invalid_config(message: impl Into<String>) -> Self {
87 ParseError::InvalidConfig(message.into())
88 }
89
90 pub fn unsupported_feature(file: impl Into<String>, feature: impl Into<String>) -> Self {
92 ParseError::UnsupportedFeature {
93 file: file.into(),
94 feature: feature.into(),
95 }
96 }
97}