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
54 changes: 52 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions crates/redis-cloud/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ impl CloudClient {
403 => Err(RestError::Forbidden { message: text }),
404 => Err(RestError::NotFound { message: text }),
412 => Err(RestError::PreconditionFailed),
429 => Err(RestError::RateLimited { message: text }),
500 => Err(RestError::InternalServerError { message: text }),
503 => Err(RestError::ServiceUnavailable { message: text }),
_ => Err(RestError::ApiError {
Expand Down Expand Up @@ -305,6 +306,7 @@ impl CloudClient {
403 => Err(RestError::Forbidden { message: text }),
404 => Err(RestError::NotFound { message: text }),
412 => Err(RestError::PreconditionFailed),
429 => Err(RestError::RateLimited { message: text }),
500 => Err(RestError::InternalServerError { message: text }),
503 => Err(RestError::ServiceUnavailable { message: text }),
_ => Err(RestError::ApiError {
Expand Down Expand Up @@ -384,6 +386,7 @@ impl CloudClient {
403 => Err(RestError::Forbidden { message: text }),
404 => Err(RestError::NotFound { message: text }),
412 => Err(RestError::PreconditionFailed),
429 => Err(RestError::RateLimited { message: text }),
500 => Err(RestError::InternalServerError { message: text }),
503 => Err(RestError::ServiceUnavailable { message: text }),
_ => Err(RestError::ApiError {
Expand Down Expand Up @@ -451,6 +454,7 @@ impl CloudClient {
403 => Err(RestError::Forbidden { message: text }),
404 => Err(RestError::NotFound { message: text }),
412 => Err(RestError::PreconditionFailed),
429 => Err(RestError::RateLimited { message: text }),
500 => Err(RestError::InternalServerError { message: text }),
503 => Err(RestError::ServiceUnavailable { message: text }),
_ => Err(RestError::ApiError {
Expand Down
21 changes: 21 additions & 0 deletions crates/redis-cloud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ pub enum CloudError {
#[error("Precondition Failed (412): Feature flag for this flow is off")]
PreconditionFailed,

#[error("Rate Limited (429): {message}")]
RateLimited { message: String },

#[error("Internal Server Error (500): {message}")]
InternalServerError { message: String },

Expand All @@ -379,6 +382,24 @@ pub enum CloudError {
JsonError(String),
}

impl CloudError {
/// Returns true if this error is retryable.
///
/// Retryable errors include:
/// - Rate limited (429)
/// - Service unavailable (503)
/// - Connection/request errors (may be transient network issues)
pub fn is_retryable(&self) -> bool {
matches!(
self,
CloudError::RateLimited { .. }
| CloudError::ServiceUnavailable { .. }
| CloudError::Request(_)
| CloudError::ConnectionError(_)
)
}
}

impl From<reqwest::Error> for CloudError {
fn from(err: reqwest::Error) -> Self {
CloudError::Request(err.to_string())
Expand Down
52 changes: 52 additions & 0 deletions crates/redis-cloud/src/lib_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,58 @@ mod tests {
assert_eq!(err.to_string(), "API error (400): Bad request");
}

#[test]
fn test_cloud_error_is_retryable() {
// Retryable errors
assert!(
CloudError::RateLimited {
message: "Too many requests".to_string()
}
.is_retryable()
);
assert!(
CloudError::ServiceUnavailable {
message: "Service down".to_string()
}
.is_retryable()
);
assert!(CloudError::Request("Connection reset".to_string()).is_retryable());
assert!(CloudError::ConnectionError("DNS failed".to_string()).is_retryable());

// Non-retryable errors
assert!(
!CloudError::BadRequest {
message: "Invalid input".to_string()
}
.is_retryable()
);
assert!(
!CloudError::AuthenticationFailed {
message: "Bad creds".to_string()
}
.is_retryable()
);
assert!(
!CloudError::Forbidden {
message: "No access".to_string()
}
.is_retryable()
);
assert!(
!CloudError::NotFound {
message: "Not found".to_string()
}
.is_retryable()
);
assert!(
!CloudError::ApiError {
code: 400,
message: "Error".to_string()
}
.is_retryable()
);
}

#[tokio::test]
async fn test_url_normalization() {
// Test various combinations of base URLs and paths to ensure no double slashes
Expand Down
2 changes: 1 addition & 1 deletion crates/redisctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ thiserror = { workspace = true }
serde_yaml = { workspace = true }
comfy-table = { workspace = true }
jmespath = { workspace = true }
jmespath_extensions = { version = "0.7", features = ["full"] }
jmespath_extensions = { version = "0.8", features = ["full"] }
config = { workspace = true }

# Keyring for Files.com API key storage (separate from profile credentials)
Expand Down
6 changes: 3 additions & 3 deletions crates/redisctl/src/cli/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ NOTE: The maximum date range is 40 days. Cost reports are generated asynchronous
redisctl cloud cost-report download cost-report-12345-abcdef

# Download cost report to a file
redisctl cloud cost-report download cost-report-12345-abcdef --output report.csv
redisctl cloud cost-report download cost-report-12345-abcdef --file report.csv

NOTE: The costReportId is returned in the task response after the generation completes.
Check task status with 'redisctl cloud task get <task-id>' to get the costReportId.
Expand All @@ -1670,8 +1670,8 @@ NOTE: The costReportId is returned in the task response after the generation com
cost_report_id: String,

/// Output file path (defaults to stdout if not specified)
#[arg(long, short)]
output: Option<String>,
#[arg(long = "file", short = 'f')]
file: Option<String>,
},
}

Expand Down
Loading
Loading