hive_router_plan_executor/executors/
error.rs1use hive_router_internal::expressions::vrl::prelude::ExpressionError;
2
3use crate::response::graphql_error::GraphQLError;
4
5#[derive(thiserror::Error, Debug, Clone)]
6pub enum SubgraphExecutorError {
7 #[error("Failed to parse endpoint \"{0}\" as URI: {1}")]
8 EndpointParseFailure(String, String),
9 #[error("Failed to compile VRL expression for subgraph '{0}'. Please check your VRL expression for syntax errors. Diagnostic: {1}")]
10 EndpointExpressionBuild(String, String),
11 #[error("Failed to resolve VRL expression for subgraph '{0}'. Runtime error: {1}")]
12 EndpointExpressionResolutionFailure(String, String),
13 #[error("VRL expression for subgraph '{0}' resolved to a non-string value.")]
14 EndpointExpressionWrongType(String),
15 #[error("Static endpoint not found for subgraph '{0}'. This is an internal error and should not happen.")]
16 StaticEndpointNotFound(String),
17 #[error("Failed to build request to subgraph \"{0}\": {1}")]
18 RequestBuildFailure(String, String),
19 #[error("Failed to send request to subgraph \"{0}\": {1}")]
20 RequestFailure(String, String),
21 #[error("Failed to serialize variable \"{0}\": {1}")]
22 VariablesSerializationFailure(String, String),
23 #[error("Failed to compile VRL expression for timeout for subgraph '{0}'. Please check your VRL expression for syntax errors. Diagnostic: {1}")]
24 RequestTimeoutExpressionBuild(String, String),
25 #[error("Failed to resolve VRL expression for timeout for subgraph '{0}'. Runtime error: {1}")]
26 TimeoutExpressionResolution(String, String),
27 #[error("Request to subgraph \"{0}\" timed out after {1} milliseconds")]
28 RequestTimeout(String, u128),
29 #[error("Failed to deserialize subgraph response: {0}")]
30 ResponseDeserializationFailure(String),
31}
32
33impl From<SubgraphExecutorError> for GraphQLError {
34 fn from(error: SubgraphExecutorError) -> Self {
35 GraphQLError::from_message_and_code("Internal server error", error.error_code())
36 }
37}
38
39impl SubgraphExecutorError {
40 pub fn new_endpoint_expression_resolution_failure(
41 subgraph_name: String,
42 error: ExpressionError,
43 ) -> Self {
44 SubgraphExecutorError::EndpointExpressionResolutionFailure(subgraph_name, error.to_string())
45 }
46
47 pub fn error_code(&self) -> &'static str {
48 match self {
49 SubgraphExecutorError::EndpointParseFailure(_, _) => "SUBGRAPH_ENDPOINT_PARSE_FAILURE",
50 SubgraphExecutorError::EndpointExpressionBuild(_, _) => {
51 "SUBGRAPH_ENDPOINT_EXPRESSION_BUILD_FAILURE"
52 }
53 SubgraphExecutorError::EndpointExpressionResolutionFailure(_, _) => {
54 "SUBGRAPH_ENDPOINT_EXPRESSION_RESOLUTION_FAILURE"
55 }
56 SubgraphExecutorError::EndpointExpressionWrongType(_) => {
57 "SUBGRAPH_ENDPOINT_EXPRESSION_WRONG_TYPE"
58 }
59 SubgraphExecutorError::StaticEndpointNotFound(_) => {
60 "SUBGRAPH_STATIC_ENDPOINT_NOT_FOUND"
61 }
62 SubgraphExecutorError::RequestBuildFailure(_, _) => "SUBGRAPH_REQUEST_BUILD_FAILURE",
63 SubgraphExecutorError::RequestFailure(_, _) => "SUBGRAPH_REQUEST_FAILURE",
64 SubgraphExecutorError::VariablesSerializationFailure(_, _) => {
65 "SUBGRAPH_VARIABLES_SERIALIZATION_FAILURE"
66 }
67 SubgraphExecutorError::TimeoutExpressionResolution(_, _) => {
68 "SUBGRAPH_TIMEOUT_EXPRESSION_RESOLUTION_FAILURE"
69 }
70 SubgraphExecutorError::RequestTimeout(_, _) => "SUBGRAPH_REQUEST_TIMEOUT",
71 SubgraphExecutorError::RequestTimeoutExpressionBuild(_, _) => {
72 "SUBGRAPH_TIMEOUT_EXPRESSION_BUILD_FAILURE"
73 }
74 SubgraphExecutorError::ResponseDeserializationFailure(_) => {
75 "SUBGRAPH_RESPONSE_DESERIALIZATION_FAILURE"
76 }
77 }
78 }
79}