From dbca96faf6b0e562c2e9e36b8c5655373bcd6869 Mon Sep 17 00:00:00 2001 From: Zhengchao An Date: Sun, 28 Jun 2026 11:21:24 +0800 Subject: [PATCH] fix(admin): improve expect() messages in user handler (#729 batch 4) (#3985) fix(admin): improve expect() messages in user handler Replace generic parse().unwrap() with parse().expect(valid header value) for better error diagnostics in user.rs. Refs https://github.com/rustfs/backlog/issues/729 --- rustfs/src/admin/handlers/user.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rustfs/src/admin/handlers/user.rs b/rustfs/src/admin/handlers/user.rs index c4a879e53..500c9de35 100644 --- a/rustfs/src/admin/handlers/user.rs +++ b/rustfs/src/admin/handlers/user.rs @@ -306,8 +306,8 @@ impl Operation for AddUser { } let mut header = HeaderMap::new(); - header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - header.insert(CONTENT_LENGTH, "0".parse().unwrap()); + header.insert(CONTENT_TYPE, "application/json".parse().expect("valid header value")); + header.insert(CONTENT_LENGTH, "0".parse().expect("valid header value")); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -366,8 +366,8 @@ impl Operation for SetUserStatus { .map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, format!("failed to set user status: {e}")))?; let mut header = HeaderMap::new(); - header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - header.insert(CONTENT_LENGTH, "0".parse().unwrap()); + header.insert(CONTENT_TYPE, "application/json".parse().expect("valid header value")); + header.insert(CONTENT_LENGTH, "0".parse().expect("valid header value")); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -431,7 +431,7 @@ impl Operation for ListUsers { let (data, content_type) = encode_compatible_admin_payload(req.uri.path(), &cred.secret_key, data)?; let mut header = HeaderMap::new(); - header.insert(CONTENT_TYPE, content_type.parse().unwrap()); + header.insert(CONTENT_TYPE, content_type.parse().expect("valid header value")); Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } @@ -532,8 +532,8 @@ impl Operation for RemoveUser { } let mut header = HeaderMap::new(); - header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); - header.insert(CONTENT_LENGTH, "0".parse().unwrap()); + header.insert(CONTENT_TYPE, "application/json".parse().expect("valid header value")); + header.insert(CONTENT_LENGTH, "0".parse().expect("valid header value")); Ok(S3Response::with_headers((StatusCode::OK, Body::empty()), header)) } } @@ -606,7 +606,7 @@ impl Operation for GetUserInfo { .map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, format!("failed to serialize response: {e}")))?; let mut header = HeaderMap::new(); - header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + header.insert(CONTENT_TYPE, "application/json".parse().expect("valid header value")); Ok(S3Response::with_headers((StatusCode::OK, Body::from(data)), header)) } @@ -840,9 +840,9 @@ impl Operation for ExportIam { .finish() .map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, e.to_string()))?; let mut header = HeaderMap::new(); - header.insert(CONTENT_TYPE, "application/zip".parse().unwrap()); - header.insert(CONTENT_DISPOSITION, "attachment; filename=iam-assets.zip".parse().unwrap()); - header.insert(CONTENT_LENGTH, zip_bytes.get_ref().len().to_string().parse().unwrap()); + header.insert(CONTENT_TYPE, "application/zip".parse().expect("valid header value")); + header.insert(CONTENT_DISPOSITION, "attachment; filename=iam-assets.zip".parse().expect("valid header value")); + header.insert(CONTENT_LENGTH, zip_bytes.get_ref().len().to_string().parse().expect("valid header value")); Ok(S3Response::with_headers((StatusCode::OK, Body::from(zip_bytes.into_inner())), header)) } } @@ -1291,7 +1291,7 @@ impl Operation for ImportIam { let body = serde_json::to_vec(&ret).map_err(|e| S3Error::with_message(S3ErrorCode::InternalError, e.to_string()))?; let mut header = HeaderMap::new(); - header.insert(CONTENT_TYPE, "application/json".parse().unwrap()); + header.insert(CONTENT_TYPE, "application/json".parse().expect("valid header value")); Ok(S3Response::with_headers((StatusCode::OK, Body::from(body)), header)) }