Skip to main content

brooks_lib/verifying/ps/
error.rs

1// brooks, Copyright 2026, Will Hawkins
2//
3// This file is part of brooks.
4
5// This file is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18use std::fmt::Display;
19
20use crate::mel::{
21    compiler::error::CompilerLocatableError as MelCompilerLocatableError,
22    error::AnalysisLocatableError as MelAnalysisLocatableError, types::Type,
23};
24
25#[derive(Debug, Clone, Default)]
26pub enum VerificationError {
27    #[default]
28    NoError,
29    WrongType,
30    WrongGenericMetadataTypeName(String, String),
31    NoVerifiedValue,
32    ExpressionCompile(Box<MelCompilerLocatableError>),
33    ExpressionAnalyze(Box<MelAnalysisLocatableError>),
34    ExpressionWrongType(Type, Type),
35    InvalidTypedResponseStage,
36    ParseError,
37}
38
39impl Display for VerificationError {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        match self {
42            VerificationError::NoError => write!(f, "No error!"),
43            VerificationError::WrongType => write!(f, "Wrong type"),
44            VerificationError::WrongGenericMetadataTypeName(expected, actual) => write!(
45                f,
46                "Wrong generic metadata type; expected {expected} and got {actual}"
47            ),
48            VerificationError::NoVerifiedValue => write!(f, "Missing verified value"),
49            VerificationError::ExpressionCompile(compiler_error) => {
50                write!(f, "Expression compilation error: {compiler_error}")
51            }
52            VerificationError::ExpressionAnalyze(mel_analysis_locatable_error) => write!(
53                f,
54                "Expression analysis error: {mel_analysis_locatable_error}"
55            ),
56            VerificationError::ExpressionWrongType(expected, actual) => write!(
57                f,
58                "Wrong expression type; expected {expected} and got {actual}"
59            ),
60            VerificationError::InvalidTypedResponseStage => {
61                write!(f, "Invalid typed response stage")
62            }
63            VerificationError::ParseError => write!(f, "Parse error"),
64        }
65    }
66}