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