qubit_value/value_error.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! # Value Processing Error Types
11//!
12//! Defines various errors that may occur during value processing.
13//!
14
15use qubit_datatype::DataType;
16use thiserror::Error;
17
18/// Value processing error type
19///
20/// Defines various error conditions that may occur during value operations.
21///
22/// # Features
23///
24/// - Type mismatch error
25/// - No value error
26/// - Type conversion failure error
27/// - Conversion error
28///
29/// # Example
30///
31/// ```rust
32/// use qubit_value::ValueError;
33///
34/// let error = ValueError::NoValue;
35/// assert_eq!(error.to_string(), "No value");
36/// ```
37///
38///
39#[derive(Debug, Error, PartialEq, Eq)]
40pub enum ValueError {
41 /// No value
42 #[error("No value")]
43 NoValue,
44
45 /// Type mismatch
46 #[error("Type mismatch: expected {expected}, actual {actual}")]
47 TypeMismatch {
48 /// Expected data type
49 expected: DataType,
50 /// Actual data type
51 actual: DataType,
52 },
53
54 /// Type conversion failed
55 #[error("Type conversion failed: from {from} to {to}")]
56 ConversionFailed {
57 /// Source data type
58 from: DataType,
59 /// Target data type
60 to: DataType,
61 },
62
63 /// Conversion error (with detailed information)
64 #[error("Conversion error: {0}")]
65 ConversionError(String),
66
67 /// Index out of bounds
68 #[error("Index out of bounds: index {index}, length {len}")]
69 IndexOutOfBounds {
70 /// Accessed index
71 index: usize,
72 /// Actual length
73 len: usize,
74 },
75
76 /// JSON serialization error
77 #[error("JSON serialization error: {0}")]
78 JsonSerializationError(String),
79
80 /// JSON deserialization error
81 #[error("JSON deserialization error: {0}")]
82 JsonDeserializationError(String),
83}
84
85/// Value processing result type
86pub type ValueResult<T> = Result<T, ValueError>;