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