Skip to main content

qubit_codec/value/
value_codec_execution_error.rs

1// =============================================================================
2//    Copyright (c) 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5// =============================================================================
6
7//! Type-erased value-codec execution errors.
8
9use std::any::TypeId;
10
11use thiserror::Error;
12
13/// Failure produced by a type-erased value-codec invocation.
14#[derive(Debug, Error)]
15pub enum ValueCodecExecutionError {
16    /// The supplied value has the wrong Rust type.
17    #[error("value codec for {expected_type} received incompatible type {actual_type:?}")]
18    TypeMismatch {
19        /// Expected diagnostic Rust type name.
20        expected_type: &'static str,
21        /// Actual process-local Rust type identity.
22        actual_type: TypeId,
23    },
24    /// The typed encoder failed.
25    #[error("value codec {codec_type} failed to encode: {source}")]
26    EncodeFailed {
27        /// Diagnostic Rust codec type name.
28        codec_type: &'static str,
29        /// Typed encoder source error.
30        #[source]
31        source: Box<dyn std::error::Error>,
32    },
33    /// The typed decoder failed.
34    #[error("value codec {codec_type} failed to decode: {source}")]
35    DecodeFailed {
36        /// Diagnostic Rust codec type name.
37        codec_type: &'static str,
38        /// Typed decoder source error.
39        #[source]
40        source: Box<dyn std::error::Error>,
41    },
42}