squawk_parser/
error.rs

1use serde::Serialize;
2
3#[derive(Debug, PartialEq, Serialize)]
4pub struct ParseError {
5    pub message: Option<String>,
6    pub funcname: Option<String>,
7    pub filename: Option<String>,
8    pub lineno: i32,
9    pub cursorpos: i32,
10    pub context: Option<String>,
11}
12
13#[derive(Debug, PartialEq, Serialize)]
14pub enum PGQueryError {
15    ParsingCString,
16    JsonParse(String),
17    QueryToCString,
18    PGParseError(ParseError),
19}
20
21impl std::convert::From<std::ffi::NulError> for PGQueryError {
22    fn from(_: std::ffi::NulError) -> Self {
23        Self::QueryToCString
24    }
25}
26
27impl std::convert::From<serde_json::error::Error> for PGQueryError {
28    fn from(e: serde_json::error::Error) -> Self {
29        Self::JsonParse(e.to_string())
30    }
31}
32
33impl std::convert::From<std::ffi::IntoStringError> for PGQueryError {
34    fn from(_: std::ffi::IntoStringError) -> Self {
35        Self::ParsingCString
36    }
37}
38
39impl std::convert::From<std::str::Utf8Error> for PGQueryError {
40    fn from(_: std::str::Utf8Error) -> Self {
41        Self::ParsingCString
42    }
43}