prism3_value/
error.rs

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