Skip to content

Core/Batch: Add handling for server errors in value conversion #3942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
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
5 changes: 5 additions & 0 deletions glide-core/src/client/value_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ pub(crate) fn convert_to_expected_type(
return Ok(value);
};

// If the value is a server error, return it as is, without conversion.
if let Value::ServerError(_) = value {
return Ok(value);
}

match expected {
ExpectedReturnType::Map {
key_type,
Expand Down
60 changes: 60 additions & 0 deletions glide-core/tests/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,66 @@ pub(crate) mod shared_client_tests {
});
}

#[rstest]
#[serial_test::serial]
#[timeout(SHORT_CLUSTER_TEST_TIMEOUT)]
fn test_pipeline_failed_commands_skip_conversion(
#[values(false, true)] use_cluster: bool,
#[values(false, true)] atomic: bool,
) {
block_on_all(async {
let mut test_basics = setup_test_basics(
use_cluster,
TestConfiguration {
shared_server: true,
..Default::default()
},
)
.await;

let mut pipeline = Pipeline::new();
if atomic {
pipeline.atomic();
}
pipeline.set("key", "value");
pipeline.hgetall("key");

let result = if atomic {
test_basics
.client
.send_transaction(&pipeline, None, None, false)
.await
.expect("Transaction failed")
} else {
test_basics
.client
.send_pipeline(
&pipeline,
None,
false,
None,
PipelineRetryStrategy {
retry_server_error: false,
retry_connection_error: false,
},
)
.await
.expect("Pipeline failed")
};

let arr = match result {
Value::Array(ref arr) => arr,
_ => panic!("Expected array result, got: {:?}", result),
};

assert_eq!(arr[0], Value::Okay, "Pipeline result: {arr:?}");
assert!(
matches!(&arr[1], Value::ServerError(err) if err.err_code().contains("WRONGTYPE")),
"Pipeline result: {arr:?}"
);
});
}

#[test]
#[serial_test::serial]
fn test_client_telemetry_standalone() {
Expand Down
Loading