qubit_value/value_wire/
value_wire_encode_error.rs1#[cfg(feature = "json")]
12use std::io::Error as IoError;
13
14#[cfg(feature = "json")]
15use qubit_budget::BudgetError;
16#[cfg(feature = "json")]
17use qubit_budget::MeasuredBudgetError;
18#[cfg(feature = "json")]
19use qubit_budget::QuantityConversionError;
20#[cfg(feature = "json")]
21use qubit_budget::json::JsonResource;
22use qubit_datatype::DataType;
23#[cfg(feature = "json")]
24use qubit_json::decode::JsonSyntaxError;
25#[cfg(feature = "json")]
26use qubit_json::encode::JsonEncodeError;
27#[cfg(feature = "json")]
28use qubit_json::encode::JsonEncodeErrorSource;
29#[cfg(feature = "json")]
30use qubit_json::encode::JsonSerializationError;
31use thiserror::Error;
32
33#[non_exhaustive]
46#[must_use]
47#[derive(Debug, Error)]
48pub enum ValueWireEncodeError {
49 #[cfg(feature = "json")]
52 #[cfg_attr(docsrs, doc(cfg(feature = "json")))]
53 #[error("V1 JSON wire cannot preserve this JSON number representation")]
54 JsonNumberNotRoundTrippable,
55 #[error("V1 JSON wire cannot represent a non-finite {data_type} value")]
57 NonFiniteFloat {
58 data_type: DataType,
60 },
61 #[error("V1 JSON wire cannot represent decimal scale {scale}; maximum absolute scale is {maximum_absolute_scale}")]
63 BigDecimalScaleTooLarge {
64 scale: i64,
66 maximum_absolute_scale: i64,
68 },
69 #[error("V1 JSON wire cannot represent UTC instant year {year}; supported years are 0 through 9999")]
71 InstantYearOutOfRange {
72 year: i32,
74 },
75 #[cfg(feature = "json")]
77 #[cfg_attr(docsrs, doc(cfg(feature = "json")))]
78 #[error("V1 JSON wire resource budget exceeded: {0}")]
79 Budget(
80 #[source]
82 BudgetError<JsonResource, usize>,
83 ),
84 #[cfg(feature = "json")]
87 #[cfg_attr(docsrs, doc(cfg(feature = "json")))]
88 #[error("V1 JSON wire resource quantity conversion failed for {resource:?}: {source}")]
89 Quantity {
90 resource: JsonResource,
92 #[source]
94 source: QuantityConversionError,
95 },
96 #[cfg(feature = "json")]
98 #[cfg_attr(docsrs, doc(cfg(feature = "json")))]
99 #[error("invalid V1 JSON wire syntax: {0}")]
100 Syntax(
101 #[source]
103 JsonSyntaxError,
104 ),
105 #[cfg(feature = "json")]
107 #[cfg_attr(docsrs, doc(cfg(feature = "json")))]
108 #[error("failed to encode V1 JSON wire value: {0}")]
109 Json(
110 #[source]
112 JsonSerializationError,
113 ),
114 #[cfg(feature = "json")]
116 #[cfg_attr(docsrs, doc(cfg(feature = "json")))]
117 #[error("failed to write V1 JSON wire value: {0}")]
118 Io(
119 #[source]
121 IoError,
122 ),
123}
124
125#[cfg(feature = "json")]
126impl From<JsonEncodeError<JsonResource, usize>> for ValueWireEncodeError {
127 #[inline]
141 fn from(error: JsonEncodeError<JsonResource>) -> Self {
142 match error.into_source() {
143 JsonEncodeErrorSource::Budget(source) => Self::from(source),
144 JsonEncodeErrorSource::InvalidRawJson(source) => Self::Syntax(source),
145 JsonEncodeErrorSource::Serialize(source) => Self::Json(source),
146 JsonEncodeErrorSource::Write(source) => Self::Io(source),
147 }
148 }
149}
150
151#[cfg(feature = "json")]
152impl From<MeasuredBudgetError<JsonResource, usize>> for ValueWireEncodeError {
153 #[inline]
166 fn from(error: MeasuredBudgetError<JsonResource, usize>) -> Self {
167 match error {
168 MeasuredBudgetError::Budget(error) => Self::Budget(error),
169 MeasuredBudgetError::Quantity { resource, source } => Self::Quantity { resource, source },
170 }
171 }
172}