haste_fhirpath/
error.rs

1use peg::str::LineCol;
2use thiserror::Error;
3
4use crate::parser::Literal;
5
6#[derive(Debug, Error)]
7pub enum OperationError {
8    #[error("Left and right have different lengths")]
9    LengthMismatch,
10    #[error("Left and right have different types {0} and {1}")]
11    TypeMismatch(&'static str, &'static str),
12    #[error("Either Left or right have an invalid types {0} {1} ")]
13    InvalidType(&'static str, &'static str),
14    #[error("Operand has invalid cardinality")]
15    InvalidCardinality,
16}
17
18#[derive(Debug, Error)]
19pub enum FunctionError {
20    #[error("Invalid function call: {0}")]
21    InvalidFunctionCall(String),
22    #[error("Invalid cardinality '{1}' for function '{0}'")]
23    InvalidCardinality(String, usize),
24}
25
26#[derive(Debug, Error)]
27pub enum FHIRPathError {
28    #[error("Invalid FHIRPath expression: {0}")]
29    ParseError(#[from] peg::error::ParseError<LineCol>),
30    #[error("Invalid literal: {0:?}")]
31    InvalidLiteral(Literal),
32    #[error("Not implemented: {0}")]
33    NotImplemented(String),
34    #[error("Internal error: {0}")]
35    InternalError(String),
36    #[error("Operation error: {0}")]
37    OperationError(OperationError),
38    #[error("Failed to downcast value to type '{0}'")]
39    FailedDowncast(String),
40    #[error("Failed to derive type name")]
41    FailedTypeNameDerivation,
42    #[error("Function error: {0}")]
43    FunctionError(#[from] FunctionError),
44}