Skip to main content

microcad_lang/value/
value_error.rs

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