Skip to main content

codex_patcher/ts/
errors.rs

1use std::path::PathBuf;
2use thiserror::Error;
3
4#[derive(Error, Debug)]
5pub enum TreeSitterError {
6    #[error("failed to initialize tree-sitter parser")]
7    ParserInit,
8
9    #[error("failed to set language for parser")]
10    LanguageSet,
11
12    #[error("failed to parse source code")]
13    ParseFailed,
14
15    #[error("invalid tree-sitter query: {message}")]
16    InvalidQuery { message: String },
17
18    #[error("query matched {count} locations, expected exactly 1")]
19    AmbiguousMatch { count: usize },
20
21    #[error("query matched 0 locations")]
22    NoMatch,
23
24    #[error("target not found: {target}")]
25    TargetNotFound { target: String },
26
27    #[error("syntax error detected at byte {byte_start}..{byte_end}")]
28    SyntaxError { byte_start: usize, byte_end: usize },
29
30    #[error("multiple syntax errors detected: {count} ERROR nodes")]
31    MultipleSyntaxErrors { count: usize },
32
33    #[error("I/O error reading {path}: {source}")]
34    Io {
35        path: PathBuf,
36        #[source]
37        source: std::io::Error,
38    },
39
40    #[error("capture '{name}' not found in query matches")]
41    CaptureNotFound { name: String },
42}