microcad_lang/value/
value_error.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Value errors.
5
6use crate::value::{error::QuantityError, *};
7use thiserror::Error;
8
9/// Value error
10#[derive(Debug, Error)]
11pub enum ValueError {
12    /// Invalid operator
13    #[error("Invalid operator: {0}")]
14    InvalidOperator(String),
15
16    /// Quantity Error.
17    #[error("Quantity error: {0}")]
18    QuantityError(#[from] QuantityError),
19
20    /// Cannot convert to color.
21    #[error("Cannot convert named tuple to color: {0}")]
22    CannotConvertToColor(Box<Tuple>),
23
24    /// Cannot add unit to a value that has already a unit
25    #[error("Cannot add unit to a value that has already a unit: {0}")]
26    CannotAddUnitToValueWithUnit(Value),
27
28    /// Cannot convert value
29    #[error("Cannot convert value {0} to {1}")]
30    CannotConvert(Value, String),
31
32    /// Cannot convert value into boolean
33    #[error("Cannot convert value into boolean: {0}")]
34    CannotConvertToBool(Value),
35
36    /// Cannot concat two vec with different types
37    #[error("Cannot concat two vec with different types {0} and {1}")]
38    CannotCombineVecOfDifferentType(Type, Type),
39
40    /// Tuple length mismatch
41    #[error("Tuple type mismatch: lhs={lhs}, rhs={rhs}")]
42    TupleTypeMismatch {
43        /// Left hand operand.
44        lhs: Type,
45        /// Right hand operand.
46        rhs: Type,
47    },
48
49    /// Duplicate parameter
50    #[error("Duplicate parameter: {0}")]
51    DuplicateParameter(Identifier),
52
53    /// Could not find identifier
54    #[error("Identifier not found: {0}")]
55    IdNotFound(Identifier),
56
57    /// Expected a common type, e.g. for a [`ValueList`].
58    #[error("Common type expected")]
59    CommonTypeExpected,
60}