Skip to content

Commit 1806abd

Browse files
committed
refactor: enhance error handling in S3 functions to include debug details
1 parent e9d5f1f commit 1806abd

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

apps/backend/src/storage.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,26 @@ fn zstd_decompress(data: &[u8]) -> Result<Vec<u8>, AppError> {
128128
Ok(out)
129129
}
130130

131-
fn s3_error(error: impl ToString) -> AppError {
132-
AppError::S3(error.to_string())
131+
fn s3_error(error: impl ToString + std::fmt::Debug) -> AppError {
132+
let display = error.to_string();
133+
let debug = format!("{error:?}");
134+
if display == debug {
135+
AppError::S3(display)
136+
} else {
137+
AppError::S3(format!("{display}; details: {debug}"))
138+
}
133139
}
134140

135-
fn s3_get_error(error: impl ToString) -> AppError {
141+
fn s3_get_error(error: impl ToString + std::fmt::Debug) -> AppError {
136142
let msg = error.to_string();
137-
if msg.contains("NoSuchKey") || msg.contains("not found") {
143+
let details = format!("{error:?}");
144+
if msg.contains("NoSuchKey")
145+
|| msg.contains("not found")
146+
|| details.contains("NoSuchKey")
147+
|| details.contains("NotFound")
148+
{
138149
AppError::NotFound
139150
} else {
140-
AppError::S3(msg)
151+
AppError::S3(format!("{msg}; details: {details}"))
141152
}
142153
}

0 commit comments

Comments
 (0)