use std::path::PathBuf;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
#[error("Parse error in {file}:{line}: {message}")]
Parse {
file: PathBuf,
line: u32,
message: String,
},
#[error("Tree-sitter error: {0}")]
TreeSitter(String),
#[error("Unsupported language: {0}")]
UnsupportedLanguage(String),
#[error("File not found: {0}")]
FileNotFound(PathBuf),
#[error("Invalid configuration: {0}")]
InvalidConfig(String),
}
impl Error {
pub fn parse(file: impl Into<PathBuf>, line: u32, message: impl Into<String>) -> Self {
Self::Parse {
file: file.into(),
line,
message: message.into(),
}
}
pub fn tree_sitter(message: impl Into<String>) -> Self {
Self::TreeSitter(message.into())
}
}