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 #[error("'{0}' is not a time unit of fixed length for date/time arithmetic")]
23 InvalidTimeUnit(String),
24}
25
26#[derive(Debug, Error)]
27pub enum FunctionError {
28 #[error("Invalid function call: {0}")]
29 InvalidFunctionCall(String),
30 #[error("Invalid cardinality '{1}' for function '{0}'")]
31 InvalidCardinality(String, usize),
32}
33
34#[derive(Debug, Error)]
35pub enum FHIRPathError {
36 #[error("Invalid FHIRPath expression: {0}")]
37 ParseError(#[from] peg::error::ParseError<LineCol>),
38 #[error("Invalid literal: {0:?}")]
39 InvalidLiteral(Literal),
40 #[error("Undefined constant: %{0}")]
41 UndefinedConstant(String),
42 #[error("Not implemented: {0}")]
43 NotImplemented(String),
44 #[error("Internal error: {0}")]
45 InternalError(String),
46 #[error("Operation error: {0}")]
47 OperationError(OperationError),
48 #[error("Failed to downcast value to type '{0}'")]
49 FailedDowncast(String),
50 #[error("Failed to derive type name")]
51 FailedTypeNameDerivation,
52 #[error("Function error: {0}")]
53 FunctionError(#[from] FunctionError),
54 #[error("Downcast error: {0}")]
55 DowncastError(#[from] haste_fhir_model::r4::conversion::DowncastError),
56}