Skip to main content

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    #[error("Collection size exceeds the maximum allowed integer limit (i64::MAX)")]
17    SizeOverflow,
18    #[error("Index must be a non-negative integer without decimal parts")]
19    InvalidIndex,
20    #[error("Index is out of bounds for the target pointer width")]
21    IndexOutOfBounds,
22}
23
24#[derive(Debug, Error)]
25pub enum FunctionError {
26    #[error("Invalid function call: {0}")]
27    InvalidFunctionCall(String),
28    #[error("Invalid cardinality '{1}' for function '{0}'")]
29    InvalidCardinality(String, usize),
30}
31
32#[derive(Debug, Error)]
33pub enum FHIRPathError {
34    #[error("Invalid FHIRPath expression: {0}")]
35    ParseError(#[from] peg::error::ParseError<LineCol>),
36    #[error("Invalid literal: {0:?}")]
37    InvalidLiteral(Literal),
38    #[error("Not implemented: {0}")]
39    NotImplemented(String),
40    #[error("Internal error: {0}")]
41    InternalError(String),
42    #[error("Operation error: {0}")]
43    OperationError(OperationError),
44    #[error("Failed to downcast value to type '{0}'")]
45    FailedDowncast(String),
46    #[error("Failed to derive type name")]
47    FailedTypeNameDerivation,
48    #[error("Function error: {0}")]
49    FunctionError(#[from] FunctionError),
50    #[error("Downcast error: {0}")]
51    DowncastError(#[from] haste_fhir_model::r4::conversion::DowncastError),
52}