diff --git a/.changesets/maint_garypen_rhai_update.md b/.changesets/maint_garypen_rhai_update.md new file mode 100644 index 0000000000..7899dcec23 --- /dev/null +++ b/.changesets/maint_garypen_rhai_update.md @@ -0,0 +1,14 @@ +### chore: Update rhai to latest release (1.19.0) ([PR #5655](https://github.com/apollographql/router/pull/5655)) + +In Rhai 1.18.0, there were changes to how exceptions within functions were created. For details see: https://github.com/rhaiscript/rhai/blob/7e0ac9d3f4da9c892ed35a211f67553a0b451218/CHANGELOG.md?plain=1#L12 + +We've modified how we handle errors raised by Rhai to comply with this change, which means error message output is affected. The change means that errors in functions will no longer document which function the error occurred in, for example: + +```diff +- "rhai execution error: 'Runtime error: I have raised an error (line 223, position 5)\nin call to function 'process_subgraph_response_string''" ++ "rhai execution error: 'Runtime error: I have raised an error (line 223, position 5)'" +``` + +Making this change allows us to keep up with the latest version (1.19.0) of Rhai. + +By [@garypen](https://github.com/garypen) in https://github.com/apollographql/router/pull/5655 diff --git a/Cargo.lock b/Cargo.lock index 4b4e884bd4..0097765ff4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5988,9 +5988,9 @@ dependencies = [ [[package]] name = "rhai" -version = "1.17.1" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6273372244d04a8a4b0bec080ea1e710403e88c5d9d83f9808b2bfa64f0982a" +checksum = "61797318be89b1a268a018a92a7657096d83f3ecb31418b9e9c16dcbb043b702" dependencies = [ "ahash", "bitflags 2.4.0", diff --git a/apollo-router/Cargo.toml b/apollo-router/Cargo.toml index 27d9151e51..540171a290 100644 --- a/apollo-router/Cargo.toml +++ b/apollo-router/Cargo.toml @@ -186,7 +186,7 @@ prost = "0.12.6" prost-types = "0.12.6" proteus = "0.5.0" rand = "0.8.5" -rhai = { version = "=1.17.1", features = ["sync", "serde", "internals"] } +rhai = { version = "1.19.0", features = ["sync", "serde", "internals"] } regex = "1.10.5" reqwest.workspace = true diff --git a/apollo-router/src/plugins/rhai/mod.rs b/apollo-router/src/plugins/rhai/mod.rs index 2f19f9cf32..8ef1e61e8f 100644 --- a/apollo-router/src/plugins/rhai/mod.rs +++ b/apollo-router/src/plugins/rhai/mod.rs @@ -792,20 +792,17 @@ fn process_error(error: Box) -> ErrorDetails { body: None, }; - // We only want to process errors raised in functions - if let EvalAltResult::ErrorInFunctionCall(..) = &*error { - let inner_error = error.unwrap_inner(); - // We only want to process runtime errors raised in functions - if let EvalAltResult::ErrorRuntime(obj, pos) = inner_error { - if let Ok(temp_error_details) = rhai::serde::from_dynamic::(obj) { - if temp_error_details.message.is_some() || temp_error_details.body.is_some() { - error_details = temp_error_details; - } else { - error_details.status = temp_error_details.status; - } + let inner_error = error.unwrap_inner(); + // We only want to process runtime errors + if let EvalAltResult::ErrorRuntime(obj, pos) = inner_error { + if let Ok(temp_error_details) = rhai::serde::from_dynamic::(obj) { + if temp_error_details.message.is_some() || temp_error_details.body.is_some() { + error_details = temp_error_details; + } else { + error_details.status = temp_error_details.status; } - error_details.position = Some(pos.into()); } + error_details.position = Some(pos.into()); } error_details } diff --git a/apollo-router/src/plugins/rhai/tests.rs b/apollo-router/src/plugins/rhai/tests.rs index f8f2d1caf3..b47c25774d 100644 --- a/apollo-router/src/plugins/rhai/tests.rs +++ b/apollo-router/src/plugins/rhai/tests.rs @@ -224,7 +224,7 @@ async fn rhai_plugin_execution_service_error() -> Result<(), BoxError> { assert_eq!( body.errors.first().unwrap().message.as_str(), - "rhai execution error: 'Runtime error: An error occured (line 30, position 5)\nin call to function 'execution_request''" + "rhai execution error: 'Runtime error: An error occured (line 30, position 5)'" ); Ok(()) } @@ -641,7 +641,7 @@ async fn it_can_process_string_subgraph_forbidden() { if let Err(error) = call_rhai_function("process_subgraph_response_string").await { let processed_error = process_error(error); assert_eq!(processed_error.status, StatusCode::INTERNAL_SERVER_ERROR); - assert_eq!(processed_error.message, Some("rhai execution error: 'Runtime error: I have raised an error (line 223, position 5)\nin call to function 'process_subgraph_response_string''".to_string())); + assert_eq!(processed_error.message, Some("rhai execution error: 'Runtime error: I have raised an error (line 223, position 5)'".to_string())); } else { // Test failed panic!("error processed incorrectly"); @@ -666,7 +666,13 @@ async fn it_cannot_process_om_subgraph_missing_message_and_body() { if let Err(error) = call_rhai_function("process_subgraph_response_om_missing_message").await { let processed_error = process_error(error); assert_eq!(processed_error.status, StatusCode::BAD_REQUEST); - assert_eq!(processed_error.message, Some("rhai execution error: 'Runtime error: #{\"status\": 400} (line 234, position 5)\nin call to function 'process_subgraph_response_om_missing_message''".to_string())); + assert_eq!( + processed_error.message, + Some( + "rhai execution error: 'Runtime error: #{\"status\": 400} (line 234, position 5)'" + .to_string() + ) + ); } else { // Test failed panic!("error processed incorrectly"); diff --git a/apollo-router/tests/integration/batching.rs b/apollo-router/tests/integration/batching.rs index 09281ea677..af682e67b2 100644 --- a/apollo-router/tests/integration/batching.rs +++ b/apollo-router/tests/integration/batching.rs @@ -377,12 +377,12 @@ async fn it_handles_cancelled_by_rhai() -> Result<(), BoxError> { entryA: index: 0 - errors: - - message: "rhai execution error: 'Runtime error: cancelled expected failure (line 5, position 13)\nin closure call'" + - message: "rhai execution error: 'Runtime error: cancelled expected failure (line 5, position 13)'" - data: entryA: index: 1 - errors: - - message: "rhai execution error: 'Runtime error: cancelled expected failure (line 5, position 13)\nin closure call'" + - message: "rhai execution error: 'Runtime error: cancelled expected failure (line 5, position 13)'" "###); } @@ -471,7 +471,7 @@ async fn it_handles_single_request_cancelled_by_rhai() -> Result<(), BoxError> { entryA: index: 1 - errors: - - message: "rhai execution error: 'Runtime error: cancelled expected failure (line 5, position 13)\nin closure call'" + - message: "rhai execution error: 'Runtime error: cancelled expected failure (line 5, position 13)'" "###); }