| ▲ | tptacek 3 hours ago |
| Probably because this case was something more akin to an assert than an error check. |
|
| ▲ | marcusb 3 hours ago | parent | next [-] |
| Rust has debug asserts for that. Using expect with a comment about why the condition should not/can't ever happen is idiomatic for cases where you never expect an Err. This reads to me more like the error type returned by append with names is not (ErrorFlags, i32) and wasn't trivially convertible into that type so someone left an unwrap in place on an "I'll fix it later" basis, but who knows. |
|
| ▲ | thundergolfer 3 hours ago | parent | prev | next [-] |
| Fly writes a lot of Rust, do you allow `unwrap()` in your production environment? At Modal we only allow `expect("...")` and the message should follow the recommended message style[1]. I'm pretty surprised that Cloudflare let an unwrap into prod that caused their worst outage in 6 years. 1. https://doc.rust-lang.org/std/option/enum.Option.html#recomm... |
| |
| ▲ | tptacek 3 hours ago | parent [-] | | After The Great If-Let Outage Of 2024, we audited all our code for that if-let/rwlock problem, changed a bunch of code, and immediately added a watchdog for deadlocks. The audit had ~no payoff; the watchdog very definitely did. I don't know enough about Cloudflare's situation to confidently recommend anything (and I certainly don't know enough to dunk on them, unlike the many Rust experts of this thread) but if I was in their shoes, I'd be a lot less interested in eradicating `unwrap` everywhere and more in making sure than an errant `unwrap` wouldn't produce stable failure modes. But like, the `unwrap` thing is all programmers here have to latch on to, and there's a psychological self-soothing instinct we all have to seize onto some root cause with a clear fix (or, better yet for dopaminergia, an opportunity to dunk). A thing I really feel in threads like this is that I'd instinctively have avoided including the detail about an `unwrap` call --- I'd have worded that part more ambiguously --- knowing (because I have a pathological affinity for this community) that this is exactly how HN would react. Maybe ironically, Prince's writing is a little better for not having dodged that bullet. | | |
| ▲ | thundergolfer 2 hours ago | parent [-] | | Fair. I agree that saying "it's the unwrap" and calling it a day is wrong. Recently actually we've done an exercise on our Worker which is "assume the worst kind of panic happens. make the Worker be ok with it". But I do feel strongly that the expect pattern is a highly useful control and that naked unwraps almost always indicate a failure to reason about the reliability of a change. An unwrap in their core proxy system indicates a problem in their change management process (review, linting, whatever). |
|
|
|
| ▲ | piperswe an hour ago | parent | prev | next [-] |
| In that case, it should probably be expect rather than unwrap, to document why the assertion should never fail. |
|
| ▲ | tristan-morris 3 hours ago | parent | prev | next [-] |
| Oh absolutely, that's how it would have been treated. Surely a unwrap_or_default() would have been a much better fit--if fetching features fails, continue processing with an empty set of rules vs stop world. |
|
| ▲ | stefan_ 3 hours ago | parent | prev [-] |
| You are saying this would not have happened in a C release build where asserts define to nothing? Wonder why these old grey beards chose to go with that. |
| |
| ▲ | tptacek 3 hours ago | parent | next [-] | | I am one of those old grey beards (or at least, I got started shipping C code in the 1990s), and I'd leave asserts in prod serverside code given the choice; better that than a totally unpredictable error path. | |
| ▲ | ashishb 3 hours ago | parent | prev [-] | | > You are saying this would not have happened in a C release build where asserts define to nothing? Afaik, Go and Java are the only languages that make you pause and explicitly deal with these exceptions. | | |
| ▲ | tristan-morris 3 hours ago | parent [-] | | And rust, but they chose to panic on the error condition. Wild. | | |
| ▲ | ashishb an hour ago | parent [-] | | > And rust, but they chose to panic on the error condition. Wild. unwrap() implicitly panic-ed, right? |
|
|
|