codeprism_lang_java/
error.rs1use std::path::Path;
4use thiserror::Error;
5
6#[derive(Error, Debug)]
8pub enum Error {
9 #[error("Parse error in {file}: {message}")]
11 Parse { file: String, message: String },
12
13 #[error("Tree-sitter error: {0}")]
15 TreeSitter(String),
16
17 #[error("Invalid Java syntax in {file} at line {line}: {message}")]
19 InvalidSyntax {
20 file: String,
21 line: usize,
22 message: String,
23 },
24
25 #[error("Unsupported Java feature in {file}: {feature}")]
27 UnsupportedFeature { file: String, feature: String },
28
29 #[error("IO error: {0}")]
31 Io(#[from] std::io::Error),
32
33 #[error("JSON error: {0}")]
35 Json(#[from] serde_json::Error),
36
37 #[error("UTF-8 error: {0}")]
39 Utf8(#[from] std::str::Utf8Error),
40}
41
42impl Error {
43 pub fn parse(file: &Path, message: &str) -> Self {
45 Self::Parse {
46 file: file.display().to_string(),
47 message: message.to_string(),
48 }
49 }
50
51 pub fn invalid_syntax(file: &Path, line: usize, message: &str) -> Self {
53 Self::InvalidSyntax {
54 file: file.display().to_string(),
55 line,
56 message: message.to_string(),
57 }
58 }
59
60 pub fn unsupported_feature(file: &Path, feature: &str) -> Self {
62 Self::UnsupportedFeature {
63 file: file.display().to_string(),
64 feature: feature.to_string(),
65 }
66 }
67}
68
69pub type Result<T> = std::result::Result<T, Error>;