Skip to main content

uqa_analysis/
error.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Errors produced while executing an analysis pipeline.
8
9use regex::Error as RegexError;
10
11use crate::token_filter::SynonymFileError;
12
13/// An invalid analyzer is an execution error, never an empty token stream.
14#[derive(Debug, thiserror::Error)]
15pub enum AnalysisError {
16    #[error("invalid {component} regular expression `{pattern}`: {source}")]
17    InvalidRegex {
18        component: &'static str,
19        pattern: String,
20        #[source]
21        source: RegexError,
22    },
23    #[error("failed to initialize built-in {component} regular expression: {message}")]
24    BuiltInRegex {
25        component: &'static str,
26        message: String,
27    },
28    #[error(
29        "invalid {component} gram bounds: min_gram must be at least 1 and max_gram must be greater than or equal to min_gram (got {min_gram}..={max_gram})"
30    )]
31    InvalidGramBounds {
32        component: &'static str,
33        min_gram: usize,
34        max_gram: usize,
35    },
36    #[error(transparent)]
37    SynonymFile(#[from] SynonymFileError),
38}
39
40pub type AnalysisResult<T> = std::result::Result<T, AnalysisError>;