codeprism_lang_js/
error.rs1use std::path::PathBuf;
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, Error>;
8
9#[derive(Debug, Error)]
11pub enum Error {
12 #[error("Parse error in {file}: {message}")]
14 Parse {
15 file: PathBuf,
17 message: String,
19 },
20
21 #[error("Failed to set language: {0}")]
23 Language(String),
24
25 #[error("Failed to extract node at {file}:{line}:{column}: {message}")]
27 NodeExtraction {
28 file: PathBuf,
30 line: usize,
32 column: usize,
34 message: String,
36 },
37
38 #[error("UTF-8 conversion error: {0}")]
40 Utf8(#[from] std::str::Utf8Error),
41
42 #[error("IO error: {0}")]
44 Io(#[from] std::io::Error),
45
46 #[error("{0}")]
48 Other(String),
49}
50
51impl Error {
52 pub fn parse(file: impl Into<PathBuf>, message: impl Into<String>) -> Self {
54 Self::Parse {
55 file: file.into(),
56 message: message.into(),
57 }
58 }
59
60 pub fn node_extraction(
62 file: impl Into<PathBuf>,
63 line: usize,
64 column: usize,
65 message: impl Into<String>,
66 ) -> Self {
67 Self::NodeExtraction {
68 file: file.into(),
69 line,
70 column,
71 message: message.into(),
72 }
73 }
74
75 pub fn language(message: impl Into<String>) -> Self {
77 Self::Language(message.into())
78 }
79
80 pub fn other(message: impl Into<String>) -> Self {
82 Self::Other(message.into())
83 }
84}