From a49d37f03d5bbe8d5bb4761d093a02d381b6beea Mon Sep 17 00:00:00 2001 From: Andre Cipriani Bandarra Date: Wed, 28 Oct 2026 08:44:53 +0000 Subject: [PATCH] refactor: address review feedback on retry_delay (#19) - Drop the unreachable checked_mul in parse_duration; a fraction of at most 9 digits scaled to nanoseconds always fits in a u32. - Share a vertex_error test helper in error.rs instead of building VertexApiError inline. - Bump version to 0.2.0 for the breaking VertexApiError.details change. --- Cargo.toml | 2 +- src/error.rs | 29 +++++++++++++++-------------- src/types/error.rs | 2 +- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4380be8..89ff856 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gemini-rs" -version = "0.1.0" +version = "0.2.0" edition = "2024" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/error.rs b/src/error.rs index 31aee5e..52922d1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -116,16 +116,18 @@ impl Error { mod tests { use super::*; + fn vertex_error(code: i32, status: &str, details: Option>) -> Error { + Error::VertexError(types::VertexApiError { + code, + message: "test".to_string(), + status: status.to_string(), + details, + }) + } + #[test] fn vertex_error_retryable_classification() { - let make_err = |code: i32, status: &str| { - Error::VertexError(types::VertexApiError { - code, - message: "test".to_string(), - status: status.to_string(), - details: None, - }) - }; + let make_err = |code: i32, status: &str| vertex_error(code, status, None); // Retryable codes assert!(make_err(429, "TOO_MANY_REQUESTS").is_retryable()); @@ -167,15 +169,14 @@ mod tests { #[test] fn retry_delay_delegates_to_vertex_error() { - let err = Error::VertexError(types::VertexApiError { - code: 429, - message: "Quota exceeded".to_string(), - status: "RESOURCE_EXHAUSTED".to_string(), - details: Some(vec![serde_json::json!({ + let err = vertex_error( + 429, + "RESOURCE_EXHAUSTED", + Some(vec![serde_json::json!({ "@type": "type.googleapis.com/google.rpc.RetryInfo", "retryDelay": "15s" })]), - }); + ); assert_eq!(err.retry_delay(), Some(Duration::from_secs(15))); assert_eq!(Error::NoCandidatesError.retry_delay(), None); diff --git a/src/types/error.rs b/src/types/error.rs index eed7b3a..be34109 100644 --- a/src/types/error.rs +++ b/src/types/error.rs @@ -92,7 +92,7 @@ fn parse_duration(s: &str) -> Option { return None; } let parsed: u32 = frac.parse().ok()?; - parsed.checked_mul(10u32.pow(9 - frac.len() as u32))? + parsed * 10u32.pow(9 - frac.len() as u32) } None => 0, };