Skip to main content

hive_router_plan_executor/executors/
error.rs

1use http::uri::InvalidUri;
2use strum::IntoStaticStr;
3
4#[derive(thiserror::Error, Debug, IntoStaticStr)]
5pub enum SubgraphExecutorError {
6    #[error("Failed to parse endpoint \"{0}\" as URI: {1}")]
7    #[strum(serialize = "SUBGRAPH_ENDPOINT_PARSE_FAILURE")]
8    EndpointParseFailure(String, InvalidUri),
9    #[error("Failed to compile VRL expression for subgraph '{0}'. Please check your VRL expression for syntax errors. Diagnostic: {1}")]
10    #[strum(serialize = "SUBGRAPH_ENDPOINT_EXPRESSION_BUILD_FAILURE")]
11    EndpointExpressionBuild(String, String),
12    #[error("Failed to resolve VRL expression. Runtime error: {0}")]
13    #[strum(serialize = "SUBGRAPH_ENDPOINT_EXPRESSION_RESOLUTION_FAILURE")]
14    EndpointExpressionResolutionFailure(String),
15    #[error("VRL expression resolved to a non-string value.")]
16    #[strum(serialize = "SUBGRAPH_ENDPOINT_EXPRESSION_WRONG_TYPE")]
17    EndpointExpressionWrongType,
18    #[error(
19        "Static endpoint not found for subgraph. This is an internal error and should not happen."
20    )]
21    #[strum(serialize = "SUBGRAPH_STATIC_ENDPOINT_NOT_FOUND")]
22    StaticEndpointNotFound,
23    #[error("Failed to build request to subgraph: {0}")]
24    #[strum(serialize = "SUBGRAPH_REQUEST_BUILD_FAILURE")]
25    RequestBuildFailure(#[from] http::Error),
26    #[error("Failed to send request to subgraph: {0}")]
27    #[strum(serialize = "SUBGRAPH_REQUEST_FAILURE")]
28    RequestFailure(#[from] hyper_util::client::legacy::Error),
29    #[error("Failed to receive response: {0}")]
30    #[strum(serialize = "SUBGRAPH_RESPONSE_FAILURE")]
31    ResponseFailure(#[from] hyper::Error),
32    #[error("Received an empty response body from subgraph")]
33    #[strum(serialize = "SUBGRAPH_EMPTY_RESPONSE_BODY")]
34    EmptyResponseBody,
35    #[error("Failed to serialize variable \"{0}\": {1}")]
36    #[strum(serialize = "SUBGRAPH_VARIABLES_SERIALIZATION_FAILURE")]
37    VariablesSerializationFailure(String, sonic_rs::Error),
38    #[error("Failed to compile VRL expression for timeout for subgraph '{0}'. Please check your VRL expression for syntax errors. Diagnostic: {0}")]
39    #[strum(serialize = "SUBGRAPH_TIMEOUT_EXPRESSION_BUILD_FAILURE")]
40    RequestTimeoutExpressionBuild(String, String),
41    #[error("Failed to resolve VRL expression for timeout for subgraph. Runtime error: {0}")]
42    #[strum(serialize = "SUBGRAPH_TIMEOUT_EXPRESSION_RESOLUTION_FAILURE")]
43    TimeoutExpressionResolution(String),
44    #[error("Request to subgraph timed out after {0} milliseconds")]
45    #[strum(serialize = "SUBGRAPH_REQUEST_TIMEOUT")]
46    RequestTimeout(u128),
47    #[error("Failed to deserialize subgraph response: {0}")]
48    #[strum(serialize = "SUBGRAPH_RESPONSE_DESERIALIZATION_FAILURE")]
49    ResponseDeserializationFailure(sonic_rs::Error),
50    #[error("Failed to initialize or load native TLS root certificates: {0}")]
51    #[strum(serialize = "SUBGRAPH_HTTPS_CERTS_FAILURE")]
52    NativeTlsCertificatesError(std::io::Error),
53}
54
55impl SubgraphExecutorError {
56    pub fn error_code(&self) -> &'static str {
57        self.into()
58    }
59}