Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changesets/maint_garypen_rhai_update.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion apollo-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 9 additions & 12 deletions apollo-router/src/plugins/rhai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,20 +792,17 @@ fn process_error(error: Box<EvalAltResult>) -> 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::<ErrorDetails>(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::<ErrorDetails>(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
}
Expand Down
12 changes: 9 additions & 3 deletions apollo-router/src/plugins/rhai/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions apollo-router/tests/integration/batching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)'"
"###);
}

Expand Down Expand Up @@ -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)'"
"###);
}

Expand Down