Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My biggest beef with "unwrap" is that it doesn't contain an error message. Because I generally follow the mantra that panics are for unrecoverable errors, (typically bugs,) some kind of error message is critical in debugging the situation. (Because no program should fail with "mystery error".)

I went back to https://doc.rust-lang.org/core/option/enum.Option.html and I can't seem to find an alternative to "unwrap" that includes an error message. I vaguely remember finding an alternative to unwrap with an error message, but because I don't use Rust on a daily basis, I can't seem to remember how I did it.



You're looking for `.expect()`, available on both Option and Result.


Perhaps expect() would work?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: