Browse Source

Disallow `.unwrap` in prod code and use expect for remaining ones

contact-taker-before-changing-cfd-state
Thomas Eizinger 3 years ago
parent
commit
499d3c6606
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 2
      daemon/src/bitmex_price_feed.rs
  2. 2
      daemon/src/lib.rs
  3. 2
      daemon/src/monitor.rs
  4. 8
      daemon/src/payout_curve.rs
  5. 2
      daemon/src/payout_curve/splineobject.rs
  6. 4
      daemon/src/to_sse_event.rs

2
daemon/src/bitmex_price_feed.rs

@ -74,7 +74,7 @@ impl Quote {
pub fn for_taker(&self) -> Usd {
// TODO: verify whether this is correct
self.mid_range().unwrap()
self.mid_range().expect("decimal arithmetic to not fail")
}
fn mid_range(&self) -> Result<Usd> {

2
daemon/src/lib.rs

@ -1,3 +1,5 @@
#![cfg_attr(not(test), warn(clippy::unwrap_used))]
pub mod actors;
pub mod auth;
pub mod bitmex_price_feed;

2
daemon/src/monitor.rs

@ -92,7 +92,7 @@ impl Actor<bdk::electrum_client::Client> {
if let Some(model::cfd::CollaborativeSettlement { tx, ..}
) = cfd.state.get_collaborative_close() {
let close_params = (tx.txid(),
tx.output.first().expect("have output").script_pubkey.clone());
tx.output.first().context("transaction has zero outputs")?.script_pubkey.clone());
actor.monitor_close_finality(close_params,cfd.order.id);
}
}

8
daemon/src/payout_curve.rs

@ -351,7 +351,7 @@ impl PayoutCurve {
vec.push(arr[[i, 1]]);
}
*arr = Array2::<f64>::from_shape_vec((capacity, 2), vec).unwrap();
*arr = Array2::<f64>::from_shape_vec((capacity, 2), vec).expect("vec is a 2D array");
}
fn modify_samples_unbounded(&self, arr: &mut Array2<f64>) {
@ -377,7 +377,7 @@ impl PayoutCurve {
vec.push(arr[[i, 1]]);
}
*arr = Array2::<f64>::from_shape_vec((capacity, 2), vec).unwrap();
*arr = Array2::<f64>::from_shape_vec((capacity, 2), vec).expect("vec is a 2D array");
}
/// this should only be used on an array `arr` that has been
@ -397,7 +397,7 @@ impl PayoutCurve {
}
}
*arr = Array2::<f64>::from_shape_vec((capacity / 3, 3), vec).unwrap();
*arr = Array2::<f64>::from_shape_vec((capacity / 3, 3), vec).expect("vec is a 2D array");
}
}
@ -446,7 +446,7 @@ fn create_long_payout_function(
vec.push(eval);
}
Array2::<f64>::from_shape_vec((t.len(), 2), vec).unwrap()
Array2::<f64>::from_shape_vec((t.len(), 2), vec).expect("vec is a 2D array")
}
}

2
daemon/src/payout_curve/splineobject.rs

@ -248,7 +248,7 @@ impl SplineObject {
// this ends up being F-contiguous, every time
let res_slice = result.select(Axis(axis_r), &idx[..]).to_owned();
let raveled = res_slice.to_shape(((n_res,), Order::C)).unwrap();
let raveled = res_slice.to_shape(((n_res,), Order::C))?;
let fixed = raveled.to_shape((res_slice.shape(), Order::C))?.to_owned();
result = fixed;

4
daemon/src/to_sse_event.rs

@ -262,8 +262,8 @@ impl ToSseEvent for CfdsWithAuxData {
// TODO: Depending on the state the margin might be set (i.e. in Open we save it
// in the DB internally) and does not have to be calculated
margin: cfd.margin().unwrap(),
margin_counterparty: cfd.counterparty_margin().unwrap(),
margin: cfd.margin().expect("margin to be available"),
margin_counterparty: cfd.counterparty_margin().expect("margin to be available"),
details,
expiry_timestamp: cfd.expiry_timestamp(),
}

Loading…
Cancel
Save