use std::io;
use std::path::PathBuf;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, ParseError>;
#[derive(Error, Debug)]
pub enum ParseError {
#[error("Failed to read file {path}: {source}")]
IoError { path: PathBuf, source: io::Error },
#[error(
"File {path} exceeds maximum size limit of {max_size} bytes (actual: {actual_size} bytes)"
)]
FileTooLarge {
path: PathBuf,
max_size: usize,
actual_size: usize,
},
#[error("Syntax error in {file} at line {line}, column {column}: {message}")]
SyntaxError {
file: String,
line: usize,
column: usize,
message: String,
},
#[error("Graph operation failed: {0}")]
GraphError(String),
#[error("Invalid configuration: {0}")]
InvalidConfig(String),
#[error("Unsupported Python feature in {file}: {feature}")]
UnsupportedFeature { file: String, feature: String },
}
impl ParseError {
pub fn io_error(path: impl Into<PathBuf>, source: io::Error) -> Self {
ParseError::IoError {
path: path.into(),
source,
}
}
pub fn file_too_large(path: impl Into<PathBuf>, max_size: usize, actual_size: usize) -> Self {
ParseError::FileTooLarge {
path: path.into(),
max_size,
actual_size,
}
}
pub fn syntax_error(
file: impl Into<String>,
line: usize,
column: usize,
message: impl Into<String>,
) -> Self {
ParseError::SyntaxError {
file: file.into(),
line,
column,
message: message.into(),
}
}
pub fn graph_error(message: impl Into<String>) -> Self {
ParseError::GraphError(message.into())
}
pub fn invalid_config(message: impl Into<String>) -> Self {
ParseError::InvalidConfig(message.into())
}
pub fn unsupported_feature(file: impl Into<String>, feature: impl Into<String>) -> Self {
ParseError::UnsupportedFeature {
file: file.into(),
feature: feature.into(),
}
}
}