codemod_core/error.rs
1//! Error types for the codemod-core crate.
2//!
3//! This module defines all error types used throughout the crate using
4//! the `thiserror` derive macro for ergonomic error handling. A unified
5//! [`CodemodError`] enum captures all possible failure modes, and a
6//! convenience [`Result`] type alias is provided.
7
8use thiserror::Error;
9
10/// Unified error type for all codemod-core operations.
11#[derive(Error, Debug)]
12pub enum CodemodError {
13 /// Pattern inference failed — the engine could not derive a
14 /// transformation pattern from the provided before/after examples.
15 #[error("Pattern inference error: {0}")]
16 PatternInference(String),
17
18 /// AST parsing failed — tree-sitter could not produce a valid
19 /// syntax tree for the given source code.
20 #[error("Parse error: {0}")]
21 Parse(String),
22
23 /// Scanning error — something went wrong while walking the
24 /// filesystem or matching patterns across files.
25 #[error("Scan error: {0}")]
26 Scan(String),
27
28 /// Transformation error — the engine failed to apply a pattern
29 /// transformation to a source file.
30 #[error("Transform error: {0}")]
31 Transform(String),
32
33 /// Rule error — a codemod rule file could not be loaded, parsed,
34 /// or failed validation.
35 #[error("Rule error: {0}")]
36 Rule(String),
37
38 /// Pattern matching error.
39 #[error("Pattern matching error: {0}")]
40 Matching(String),
41
42 /// File I/O error — a filesystem operation (read, write, create
43 /// directory, etc.) failed.
44 #[error("IO error: {0}")]
45 Io(#[from] std::io::Error),
46
47 /// YAML serialization/deserialization error.
48 #[error("YAML error: {0}")]
49 Yaml(#[from] serde_yaml::Error),
50
51 /// JSON serialization/deserialization error.
52 #[error("JSON error: {0}")]
53 Json(#[from] serde_json::Error),
54
55 /// Language not supported.
56 #[error("Language not supported: {0}")]
57 UnsupportedLanguage(String),
58
59 /// Validation failed.
60 #[error("Validation failed: {0}")]
61 Validation(String),
62
63 /// Catch-all for other errors.
64 #[error("{0}")]
65 Other(String),
66}
67
68/// Convenience result type for codemod-core operations.
69pub type Result<T> = std::result::Result<T, CodemodError>;