ws_msg.data.B.parse::<f64>().map_err(|_| SimpleError::new("Failed to parse ws_msg.data.B"));
Besides, I recommended replacing SimpleError to anyhow. It allows us wrapping all the error with a generic Error:
fn parse() -> anyhow::Result<T> {
// Even simpler than `.unwrap()`. Besides, the `parse()` is recoverable now!
ws_msg.data.B.parse::<f64>()?;
// If you need context:
ws_msg.data.B.parse::<f64>().context("Failed to parse ws_msg.data.B")?;
}
TBDs (To Be Discussed)
[ ] Use anyhow or remain SimpleError? I prefer former.
[ ] Migrate it with less breaking changes (or just make it without writing too many “runtime” to unwrap)
Abstract
crypto-crawler
panics when the data format is invalid, which may have better recoverable way to indicate instead of just aborting the whole tasks.Solution
Replace all of them to
Result<T, SimpleError>
:Besides, I recommended replacing
SimpleError
toanyhow
. It allows us wrapping all the error with a generic Error:TBDs (To Be Discussed)
anyhow
or remainSimpleError
? I prefer former.