#[cfg(feature = "json")]
use std::io::Error as IoError;
#[cfg(feature = "json")]
use qubit_budget::BudgetError;
#[cfg(feature = "json")]
use qubit_budget::MeasuredBudgetError;
#[cfg(feature = "json")]
use qubit_budget::QuantityConversionError;
#[cfg(feature = "json")]
use qubit_budget::json::JsonResource;
use qubit_datatype::DataType;
#[cfg(feature = "json")]
use qubit_json::decode::JsonSyntaxError;
#[cfg(feature = "json")]
use qubit_json::encode::JsonEncodeError;
#[cfg(feature = "json")]
use qubit_json::encode::JsonEncodeErrorSource;
#[cfg(feature = "json")]
use qubit_json::encode::JsonSerializationError;
use thiserror::Error;
#[non_exhaustive]
#[must_use]
#[derive(Debug, Error)]
pub enum ValueWireEncodeError {
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
#[error("V1 JSON wire cannot preserve this JSON number representation")]
JsonNumberNotRoundTrippable,
#[error("V1 JSON wire cannot represent a non-finite {data_type} value")]
NonFiniteFloat {
data_type: DataType,
},
#[error("V1 JSON wire cannot represent decimal scale {scale}; maximum absolute scale is {maximum_absolute_scale}")]
BigDecimalScaleTooLarge {
scale: i64,
maximum_absolute_scale: i64,
},
#[error("V1 JSON wire cannot represent UTC instant year {year}; supported years are 0 through 9999")]
InstantYearOutOfRange {
year: i32,
},
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
#[error("V1 JSON wire resource budget exceeded: {0}")]
Budget(
#[source]
BudgetError<JsonResource, usize>,
),
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
#[error("V1 JSON wire resource quantity conversion failed for {resource:?}: {source}")]
Quantity {
resource: JsonResource,
#[source]
source: QuantityConversionError,
},
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
#[error("invalid V1 JSON wire syntax: {0}")]
Syntax(
#[source]
JsonSyntaxError,
),
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
#[error("failed to encode V1 JSON wire value: {0}")]
Json(
#[source]
JsonSerializationError,
),
#[cfg(feature = "json")]
#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
#[error("failed to write V1 JSON wire value: {0}")]
Io(
#[source]
IoError,
),
}
#[cfg(feature = "json")]
impl From<JsonEncodeError<JsonResource, usize>> for ValueWireEncodeError {
#[inline]
fn from(error: JsonEncodeError<JsonResource>) -> Self {
match error.into_source() {
JsonEncodeErrorSource::Budget(source) => Self::from(source),
JsonEncodeErrorSource::InvalidRawJson(source) => Self::Syntax(source),
JsonEncodeErrorSource::Serialize(source) => Self::Json(source),
JsonEncodeErrorSource::Write(source) => Self::Io(source),
}
}
}
#[cfg(feature = "json")]
impl From<MeasuredBudgetError<JsonResource, usize>> for ValueWireEncodeError {
#[inline]
fn from(error: MeasuredBudgetError<JsonResource, usize>) -> Self {
match error {
MeasuredBudgetError::Budget(error) => Self::Budget(error),
MeasuredBudgetError::Quantity { resource, source } => Self::Quantity { resource, source },
}
}
}