Skip to main content

ic_response_verification/cel/
error.rs

1pub(crate) type CelParserResult<T = ()> = Result<T, CelParserError>;
2
3/// CEL expression parsing error.
4#[derive(thiserror::Error, Debug, Clone)]
5pub enum CelParserError {
6    /// The CEL parser encountered an unsupported CEL function.
7    #[error(r#""{0}" is not a supported CEL function, only default_certification is currently supported"#)]
8    UnrecognizedFunction(String),
9
10    /// The CEL parser expected a parameter at a position, but none was found.
11    #[error(r#"Parameter at position {parameter_position:?} for function {function_name:?} is missing, expected {parameter_name:?} with type {parameter_type:?}"#)]
12    MissingFunctionParameter {
13        /// The name of the function with a missing parameter.
14        function_name: String,
15        /// The expected type of the missing parameter.
16        parameter_type: String,
17        /// The expected name of the missing parameter.
18        parameter_name: String,
19        /// The expected position of the missing parameter.
20        parameter_position: u8,
21    },
22
23    /// The CEL parser expected a parameter to have a different type than the one it found.
24    #[error(r#"Parameter at position {parameter_position:?} for function {function_name:?} has the wrong type, expected {parameter_name:?} {expected_parameter_type:?} found {found_parameter_type:?}"#)]
25    IncorrectFunctionParameterType {
26        /// The name of the function with an unexpected parameter type.
27        function_name: String,
28        /// The name of the parameter with the unexpected type.
29        parameter_name: String,
30        /// The expected type of the parameter.
31        expected_parameter_type: String,
32        /// The actual type of the parameter.
33        found_parameter_type: String,
34        /// The position of the parameter.
35        parameter_position: u8,
36    },
37
38    /// The CEL parser expected a node to have a different type than the one it found.
39    #[error(r#"Expected node with name {node_name:?} to have type {expected_type:?}, found {found_type:?}"#)]
40    UnexpectedNodeType {
41        /// The name of the node with an unexpected type.
42        node_name: String,
43        /// The expected type of the node.
44        expected_type: String,
45        /// The actual type of the node.
46        found_type: String,
47    },
48
49    /// The CEL parser expected a node to have a different name than the one it found.
50    #[error(r#"Expected node with type {node_type:?} to have name {expected_name:?}, found {found_name:?}"#)]
51    UnexpectedNodeName {
52        /// The type of the node with an unexpected name.
53        node_type: String,
54        /// The expected name of the node.
55        expected_name: String,
56        /// The actual name of hte node.
57        found_name: String,
58    },
59
60    /// The CEL parser expected an object to have a property with a particular name, but none was found.
61    #[error(r#"Expected object {object_name:?} to have property {expected_property_name:?}"#)]
62    MissingObjectProperty {
63        /// The name of the object with a missing property.
64        object_name: String,
65        /// The expected property name.
66        expected_property_name: String,
67    },
68
69    /// The CEL parser encountered an extraneous property on the request certification's CEL object.
70    #[error(r#"The request_certification object must only specify one of the no_request_certification or request_certification properties, not both"#)]
71    ExtraneousRequestCertificationProperty,
72
73    /// The CEL parser expected to find a property on the request certification's CEL object, but none was found.
74    #[error(r#"The request_certification object must specify at least one of the no_request_certification or request_certification properties"#)]
75    MissingRequestCertificationProperty,
76
77    /// The CEL parser encountered an extraneous property on the response certification's CEL object.
78    #[error(r#"The response_certification object must only specify one of the certified_response_headers or response_header_exclusions properties, not both"#)]
79    ExtraneousResponseCertificationProperty,
80
81    /// The CEL parser expected to find a property on the response certification's CEL object, but none was found.
82    #[error(r#"The response_certification object must specify at least one of the certified_response_headers or response_header_exclusions properties"#)]
83    MissingResponseCertificationProperty,
84
85    /// The CEL parser encountered an extraneous property on the certification's CEL object.
86    #[error(r#"The ValidationArgs parameter must only specify one of the no_certification or certification properties, not both"#)]
87    ExtraneousValidationArgsProperty,
88
89    /// The CEL parser expected to find a property on the certification's CEL object, but none was found.
90    #[error(r#"The ValidationArgs parameter must specify at least one of the no_certification or certification properties"#)]
91    MissingValidationArgsProperty,
92
93    /// The CEL parser encountered a syntax error while parsing the CEL expression. Using the "debug" feature flag can help to debug these syntax errors.
94    #[error(r#"Cel Syntax Expception: {0}"#)]
95    CelSyntaxException(String),
96}