Skip to content

Commit 5deaedc

Browse files
committed
Improve test for logging of chained errors
Explicitly test that chained errors within a public facing error produce a sequence of "casued by" to be logged.
1 parent 6a10df1 commit 5deaedc

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/middleware/log_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(crate) fn get_log_message(req: &dyn Request, key: &'static str) -> String {
6565
return v.clone();
6666
}
6767
}
68-
String::new()
68+
panic!("expected log message for {} not found", key);
6969
}
7070

7171
struct RequestLine<'r> {

src/router.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ mod tests {
230230
let response = C(|_| {
231231
Err("-1"
232232
.parse::<u8>()
233+
.chain_error(|| internal("middle error"))
233234
.chain_error(|| bad_request("outer user facing error"))
234235
.unwrap_err())
235236
})
@@ -238,7 +239,7 @@ mod tests {
238239
assert_eq!(response.status.0, 400);
239240
assert_eq!(
240241
crate::middleware::log_request::get_log_message(&req, "cause"),
241-
"invalid digit found in string"
242+
"middle error caused by invalid digit found in string"
242243
);
243244

244245
// All other error types are propogated up the middleware, eventually becoming status 500

0 commit comments

Comments
 (0)