Skip to main content

pg_jsonl/
error.rs

1//! PG-JSONL parser error types.
2
3/// Errors from parsing PG-JSONL files.
4#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
5pub enum PgJsonlError {
6    /// A line is not a valid JSON object of a known record shape.
7    #[error("PG-JSONL: line {line}: {detail}")]
8    Json {
9        /// 1-based line number.
10        line: usize,
11        /// The JSON parser's failure detail.
12        detail: String,
13    },
14
15    /// A record's `type` is neither `node` nor `edge`/`relationship`.
16    #[error("PG-JSONL: line {line}: unknown record type '{kind}'")]
17    UnknownType {
18        /// 1-based line number.
19        line: usize,
20        /// The offending `type` value.
21        kind: String,
22    },
23
24    /// An identifier field is empty.
25    #[error("PG-JSONL: line {line}: '{field}' must not be empty")]
26    EmptyField {
27        /// 1-based line number.
28        line: usize,
29        /// The field name.
30        field: &'static str,
31    },
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37
38    #[test]
39    fn display_unknown_type() {
40        let err = PgJsonlError::UnknownType {
41            line: 3,
42            kind: "vertex".to_owned(),
43        };
44        assert_eq!(
45            err.to_string(),
46            "PG-JSONL: line 3: unknown record type 'vertex'"
47        );
48    }
49}