ngdp_bpsv/
error.rs

1//! Error types for BPSV parsing and building
2
3use thiserror::Error;
4
5/// Result type for BPSV operations
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur during BPSV operations
9#[derive(Error, Debug, Clone, PartialEq)]
10pub enum Error {
11    /// Error parsing field type specification
12    #[error("Invalid field type: {field_type}")]
13    InvalidFieldType { field_type: String },
14
15    /// Error parsing header line
16    #[error("Invalid header format: {reason}")]
17    InvalidHeader { reason: String },
18
19    /// Error parsing sequence number
20    #[error("Invalid sequence number: {line}")]
21    InvalidSequenceNumber { line: String },
22
23    /// Mismatch between schema and data
24    #[error("Schema mismatch: expected {expected} fields, got {actual}")]
25    SchemaMismatch { expected: usize, actual: usize },
26
27    /// Invalid value for field type
28    #[error("Invalid value for field '{field}' of type {field_type}: {value}")]
29    InvalidValue {
30        field: String,
31        field_type: String,
32        value: String,
33    },
34
35    /// Missing required header
36    #[error("Missing header line")]
37    MissingHeader,
38
39    /// Empty document
40    #[error("Document is empty")]
41    EmptyDocument,
42
43    /// Field not found in schema
44    #[error("Field '{field}' not found in schema")]
45    FieldNotFound { field: String },
46
47    /// Duplicate field name
48    #[error("Duplicate field name: {field}")]
49    DuplicateField { field: String },
50
51    /// Row validation error
52    #[error("Row {row_index} validation failed: {reason}")]
53    RowValidation { row_index: usize, reason: String },
54
55    /// Hex decoding error
56    #[error("Invalid hex value: {value}")]
57    InvalidHex { value: String },
58
59    /// Number parsing error
60    #[error("Invalid number: {value}")]
61    InvalidNumber { value: String },
62
63    /// IO error during parsing or writing
64    #[error("IO error: {0}")]
65    Io(String),
66}