Skip to main content

eure_json/
error.rs

1use eure_document::document::NodeId;
2use thiserror::Error;
3
4#[derive(Debug, Clone, Error, PartialEq)]
5pub enum EureToJsonError {
6    #[error("Hole (uninitialized value) is not supported in JSON")]
7    HoleNotSupported { node_id: NodeId },
8
9    #[error("PartialMap (map with hole keys) is not supported in JSON")]
10    PartialMapNotSupported { node_id: NodeId },
11
12    #[error("BigInt value is out of range for JSON number")]
13    BigIntOutOfRange { node_id: NodeId },
14
15    #[error("Non-finite floating point value (NaN or Infinity) is not supported in JSON")]
16    NonFiniteFloat { node_id: NodeId },
17
18    #[error("Variant content already contains tag field '{tag}' in Internal representation")]
19    VariantTagConflict { tag: String, node_id: NodeId },
20
21    #[error("Variant content already contains field '{field}' in Adjacent representation")]
22    VariantAdjacentConflict { field: String, node_id: NodeId },
23}
24
25impl EureToJsonError {
26    /// Returns the NodeId associated with this error.
27    pub fn node_id(&self) -> NodeId {
28        match self {
29            EureToJsonError::HoleNotSupported { node_id } => *node_id,
30            EureToJsonError::PartialMapNotSupported { node_id } => *node_id,
31            EureToJsonError::BigIntOutOfRange { node_id } => *node_id,
32            EureToJsonError::NonFiniteFloat { node_id } => *node_id,
33            EureToJsonError::VariantTagConflict { node_id, .. } => *node_id,
34            EureToJsonError::VariantAdjacentConflict { node_id, .. } => *node_id,
35        }
36    }
37}
38
39/// Errors that can occur when converting JSON to Eure.
40/// Currently this is infallible, but the error type is provided for future extensibility
41/// and API consistency.
42#[derive(Debug, Error, PartialEq)]
43pub enum JsonToEureError {
44    // Currently no error cases - JSON to Eure conversion is infallible.
45    // This enum is provided for:
46    // 1. API consistency with EureToJsonError
47    // 2. Future extensibility (e.g., schema-guided conversion constraints)
48}