Skip to main content

qubit_value/value_wire/
value_wire_encode_error.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8
9//! Errors produced while constructing a V1 wire DTO.
10
11use qubit_datatype::DataType;
12use thiserror::Error;
13
14/// A runtime value cannot be represented by the JSON V1 wire contract.
15#[derive(Debug, Clone, Error, PartialEq, Eq)]
16#[non_exhaustive]
17pub enum ValueWireEncodeError {
18    /// A JSON V1 float must be finite.
19    #[error("V1 JSON wire cannot represent a non-finite {data_type} value")]
20    NonFiniteFloat {
21        /// Runtime data type of the rejected value.
22        data_type: DataType,
23    },
24    /// A V1 decimal exponent must stay within the bounded wire range.
25    #[error(
26        "V1 JSON wire cannot represent decimal scale {scale}; maximum absolute scale is {maximum_absolute_scale}"
27    )]
28    BigDecimalScaleTooLarge {
29        /// Rejected decimal exponent.
30        scale: i64,
31        /// Inclusive exponent magnitude limit for V1.
32        maximum_absolute_scale: i64,
33    },
34    /// A JSON V1 object uses serde_json's private number marker key.
35    #[cfg(feature = "json")]
36    #[error(
37        "V1 JSON wire cannot represent an object containing the reserved key '{key}'"
38    )]
39    ReservedJsonObjectKey {
40        /// Key reserved by serde_json's arbitrary-precision representation.
41        key: &'static str,
42    },
43}