Skip to content

Commit e7a11ae

Browse files
jchrostek-ddclaude
andcommitted
Fix clippy and formatting issues in OTLP code
- Replace unwrap() with expect() in tests (clippy::unwrap_used) - Apply cargo fmt formatting fixes 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7fb0479 commit e7a11ae

2 files changed

Lines changed: 25 additions & 18 deletions

File tree

bottlecap/src/otlp/agent.rs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,11 @@ impl Agent {
221221
Self::otlp_success_response(encoding)
222222
}
223223

224-
fn otlp_error_response(status_code: StatusCode, message: String, encoding: OtlpEncoding) -> Response {
224+
fn otlp_error_response(
225+
status_code: StatusCode,
226+
message: String,
227+
encoding: OtlpEncoding,
228+
) -> Response {
225229
let body = match encoding {
226230
OtlpEncoding::Json => {
227231
// For JSON, use a simple JSON error object since tonic_types::Status
@@ -234,7 +238,8 @@ impl Agent {
234238
Ok(buf) => buf,
235239
Err(e) => {
236240
error!("OTLP | Failed to encode error response as JSON: {e}");
237-
return (status_code, [(header::CONTENT_TYPE, "text/plain")], message).into_response();
241+
return (status_code, [(header::CONTENT_TYPE, "text/plain")], message)
242+
.into_response();
238243
}
239244
}
240245
}
@@ -247,7 +252,8 @@ impl Agent {
247252
let mut buf = Vec::new();
248253
if let Err(e) = status.encode(&mut buf) {
249254
error!("OTLP | Failed to encode error response: {e}");
250-
return (status_code, [(header::CONTENT_TYPE, "text/plain")], message).into_response();
255+
return (status_code, [(header::CONTENT_TYPE, "text/plain")], message)
256+
.into_response();
251257
}
252258
buf
253259
}
@@ -267,19 +273,17 @@ impl Agent {
267273
};
268274

269275
let body = match encoding {
270-
OtlpEncoding::Json => {
271-
match serde_json::to_vec(&response) {
272-
Ok(buf) => buf,
273-
Err(e) => {
274-
error!("OTLP | Failed to encode success response as JSON: {e}");
275-
return (
276-
StatusCode::INTERNAL_SERVER_ERROR,
277-
"Failed to encode response".to_string(),
278-
)
279-
.into_response();
280-
}
276+
OtlpEncoding::Json => match serde_json::to_vec(&response) {
277+
Ok(buf) => buf,
278+
Err(e) => {
279+
error!("OTLP | Failed to encode success response as JSON: {e}");
280+
return (
281+
StatusCode::INTERNAL_SERVER_ERROR,
282+
"Failed to encode response".to_string(),
283+
)
284+
.into_response();
281285
}
282-
}
286+
},
283287
OtlpEncoding::Protobuf => {
284288
let mut buf = Vec::new();
285289
if let Err(e) = response.encode(&mut buf) {

bottlecap/src/otlp/processor.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ mod tests {
120120
#[test]
121121
fn test_otlp_encoding_content_type() {
122122
assert_eq!(OtlpEncoding::Json.content_type(), "application/json");
123-
assert_eq!(OtlpEncoding::Protobuf.content_type(), "application/x-protobuf");
123+
assert_eq!(
124+
OtlpEncoding::Protobuf.content_type(),
125+
"application/x-protobuf"
126+
);
124127
}
125128

126129
#[test]
@@ -135,7 +138,7 @@ mod tests {
135138

136139
let result = processor.process(&body, OtlpEncoding::Protobuf);
137140
assert!(result.is_ok());
138-
assert!(result.unwrap().is_empty());
141+
assert!(result.expect("process should succeed").is_empty());
139142
}
140143

141144
#[test]
@@ -147,7 +150,7 @@ mod tests {
147150

148151
let result = processor.process(body, OtlpEncoding::Json);
149152
assert!(result.is_ok());
150-
assert!(result.unwrap().is_empty());
153+
assert!(result.expect("process should succeed").is_empty());
151154
}
152155

153156
#[test]

0 commit comments

Comments
 (0)