3 ms·
It was bad coding. .unwrap() is not required to be used. use: if let Some(value)=something_to_unwrap{ }else{ // log an error and exit!! }
by dana321 11mo ago
It was bad coding.
.unwrap() is not required to be used.
use:
if let Some(value)=something_to_unwrap{
}else{
// log an error and exit!!
}
- Measter 11mo agoFun fact: that's what an unwrap does. It panics, which causes the error to be logged and the thread ended.
- drannex 11mo agoAnd one of the fun things about how unwrap() does that automatically, is that if you are working with an orchestrator with retry logic, you won't need to (re-re-re-re-re-)write your own for the entire program - the orchestrator will see the error, log its output, and try again in high volume workloads, or move on to the next request - this is incredible and nice to use especially when a failure in one request doesn't need to fail the entire application for all requests. I shy away from unwrap() in almost all cases (as should anyone!) but if you are running a modular system, then unwrap when placed strategically can be incredibly useful.
- leoh 11mo agoI think the commenter meant "return a Result<_>" instead of exit. Your snark is perhaps amusing, but not particularly charitable.
- nrds 11mo agoMaybe rust should put a function in the core library which does this! Send a PR!
- 15155 11mo agohttps://doc.rust-lang.org/std/result/enum.Result.html#method.expect https://doc.rust-lang.org/std/result/enum.Result.html#method...