forge
Explore
Log in

Don't you dare go Hollow

project_note

Clone
★ 0

0 watching0 forksRust3.6 MiBc49f5e7Tahinli1 month ago2 commits

errors.rs61 lines, 1.4 KiBHistoryRawDownload
1use std::fmt;
2
3#[derive(Debug)]
4pub enum JSONPathErrorType {
5 LexerError,
6 SyntaxError,
7 TypeError,
8 NameError,
9}
10
11#[derive(Debug)]
12pub struct JSONPathError {
13 pub kind: JSONPathErrorType,
14 pub msg: String,
15}
16
17impl JSONPathError {
18 pub fn new(error: JSONPathErrorType, msg: String) -> Self {
19 Self { kind: error, msg }
20 }
21
22 pub fn syntax(msg: String) -> Self {
23 Self {
24 kind: JSONPathErrorType::SyntaxError,
25 msg,
26 }
27 }
28
29 pub fn typ(msg: String) -> Self {
30 Self {
31 kind: JSONPathErrorType::TypeError,
32 msg,
33 }
34 }
35
36 pub fn name(msg: String) -> Self {
37 Self {
38 kind: JSONPathErrorType::NameError,
39 msg,
40 }
41 }
42}
43
44impl fmt::Display for JSONPathErrorType {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 match self {
47 JSONPathErrorType::LexerError => f.write_str("lexer error:"),
48 JSONPathErrorType::SyntaxError => f.write_str("syntax error:"),
49 JSONPathErrorType::TypeError => f.write_str("type error:"),
50 JSONPathErrorType::NameError => f.write_str("name error:"),
51 }
52 }
53}
54
55impl std::error::Error for JSONPathError {}
56
57impl fmt::Display for JSONPathError {
58 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
59 write!(f, "{}", self.msg)
60 }
61}