Skip to main content

epsg_utils/
error.rs

1#[derive(Debug, PartialEq)]
2pub enum ParseError {
3    UnexpectedEnd,
4    UnexpectedChar {
5        expected: char,
6        found: char,
7        pos: usize,
8    },
9    UnexpectedKeyword {
10        keyword: String,
11        pos: usize,
12    },
13    ExpectedKeyword {
14        pos: usize,
15    },
16    UnterminatedString {
17        pos: usize,
18    },
19    TrailingInput {
20        pos: usize,
21    },
22    InvalidJson {
23        message: String,
24    },
25    UnknownEpsgCode {
26        code: i32,
27    },
28}
29
30impl std::fmt::Display for ParseError {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        match self {
33            ParseError::UnexpectedEnd => write!(f, "unexpected end of input"),
34            ParseError::UnexpectedChar {
35                expected,
36                found,
37                pos,
38            } => {
39                write!(
40                    f,
41                    "expected '{expected}', found '{found}' at position {pos}"
42                )
43            }
44            ParseError::UnexpectedKeyword { keyword, pos } => {
45                write!(f, "unexpected keyword '{keyword}' at position {pos}")
46            }
47            ParseError::ExpectedKeyword { pos } => {
48                write!(f, "expected keyword at position {pos}")
49            }
50            ParseError::UnterminatedString { pos } => {
51                write!(f, "unterminated string starting at position {pos}")
52            }
53            ParseError::TrailingInput { pos } => {
54                write!(f, "trailing input at position {pos}")
55            }
56            ParseError::InvalidJson { message } => {
57                write!(f, "invalid PROJJSON: {message}")
58            }
59            ParseError::UnknownEpsgCode { code } => {
60                write!(f, "unknown EPSG code: {code}")
61            }
62        }
63    }
64}
65
66impl std::error::Error for ParseError {}