From e5a355efe90f1fd0af4cf90cd1b1e30401031c75 Mon Sep 17 00:00:00 2001 From: Zhengchao An Date: Sun, 28 Jun 2026 11:21:51 +0800 Subject: [PATCH] fix(admin): improve expect() messages in policies handler (#729 batch 5) (#3986) fix(admin): improve expect() messages in policies handler Replace generic parse().unwrap() with parse().expect(valid header value) for better error diagnostics in policies.rs. Refs https://github.com/rustfs/backlog/issues/729 --- rustfs/src/admin/handlers/policies.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/rustfs/src/admin/handlers/policies.rs b/rustfs/src/admin/handlers/policies.rs index 6f5b78724..8d7bf016d 100644 --- a/rustfs/src/admin/handlers/policies.rs +++ b/rustfs/src/admin/handlers/policies.rs @@ -169,7 +169,7 @@ impl Operation for ListCannedPolicies { let body = serde_json::to_vec(&kvs).map_err(|e| s3_error!(InternalError, "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(body)), header)) } @@ -294,8 +294,8 @@ impl Operation for AddCannedPolicy { } 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)) } } @@ -360,7 +360,7 @@ impl Operation for InfoCannedPolicy { let body = serde_json::to_vec(&pd).map_err(|e| s3_error!(InternalError, "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(body)), header)) } @@ -440,8 +440,8 @@ impl Operation for RemoveCannedPolicy { } 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)) } } @@ -597,8 +597,8 @@ impl Operation for SetPolicyForUserOrGroup { } 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)) } } @@ -932,8 +932,8 @@ async fn handle_builtin_policy_entities(req: S3Request) -> S3Result, is_attach: bool let (body, content_type) = encode_compatible_admin_payload(&req_path, &cred.secret_key, body)?; let mut header = HeaderMap::new(); - header.insert(CONTENT_TYPE, content_type.parse().unwrap()); - header.insert(CONTENT_LENGTH, body.len().to_string().parse().unwrap()); + header.insert(CONTENT_TYPE, content_type.parse().expect("valid header value")); + header.insert(CONTENT_LENGTH, body.len().to_string().parse().expect("valid header value")); Ok(S3Response::with_headers((StatusCode::OK, Body::from(body)), header)) }