api_server: replace unwrap with expect
@@ -465,7 +465,9 @@ impl hyper::server::Service for ApiServerHttpService {
METRICS.get_api_requests.instance_info_count.inc();
// unwrap() to crash if the other thread poisoned this lock
- let shared_info = shared_info_lock.read().unwrap();
+ let shared_info = shared_info_lock
+ .read()
+ .expect("Failed to read shared_info due to poisoned lock");
// Serialize it to a JSON string.
let body_result = serde_json::to_string(&(*shared_info));
match body_result {
@@ -481,7 +483,9 @@ impl hyper::server::Service for ApiServerHttpService {
}
}
PatchMMDS(json_value) => {
- let mut mmds = mmds_info.lock().unwrap();
+ let mut mmds = mmds_info
+ .lock()
+ .expect("Failed to acquire lock on MMDS info");
match mmds.is_initialized() {
true => {
mmds.patch_data(json_value);
@@ -494,12 +498,18 @@ impl hyper::server::Service for ApiServerHttpService {
}
}
PutMMDS(json_value) => {
- mmds_info.lock().unwrap().put_data(json_value);
+ mmds_info
+ .lock()
+ .expect("Failed to acquire lock on MMDS info")
+ .put_data(json_value);
Either::A(future::ok(empty_response(StatusCode::NoContent)))
}
GetMMDS => Either::A(future::ok(json_response(
StatusCode::Ok,
- mmds_info.lock().unwrap().get_data_str(),
+ mmds_info
+ .lock()
+ .expect("Failed to acquire lock on MMDS info")
+ .get_data_str(),
))),
Sync(sync_req, outcome_receiver) => {
if send_to_vmm(sync_req, &api_request_sender, &vmm_send_event).is_err() {
@@ -597,7 +607,10 @@ mod tests {
Ok::<_, hyper::Error>(acc)
}).and_then(move |value| Ok(value));
- String::from_utf8_lossy(&ret.wait().unwrap()).into()
+ String::from_utf8_lossy(
+ &ret.wait()
+ .expect("Couldn't convert request body into String due to Future polling failure"),
+ ).into()
}
fn get_dummy_serde_error() -> serde_json::Error {
