Hacker News new | past | comments | ask | show | jobs | submit login

How does anyone on the stack above handle this error? i.e. what can be done programmatically to deal with it?

I claim this is far worse than panic in this case... you've now introduced a code path variant that folks above think is "legitimate" or caused by some input or something in the environment that could be changed to make it go away... but that's not the case here... the only thing that can be fixed is the code in question to not be in this region if the array length is 2 or less. It's a plain old "bug" and the only cure (other than more cowbell) is to modify source and recompile.




> How does anyone on the stack above handle this error? For a web application, you respond to the request with 5xx error.

Applications do many things. A degraded state (e.g. a single endpoint being broken) is often preferable to a full crash. It's very little effort to opt in to panics by calling unwrap(). It's a lot of effort to recover from panics. Let me, as the caller, make that decision.


But any standard web framework already would use a panic handler to turn a panic within application code to a 5xx error.


Here's a discussion on actix-web and panic handlers: https://github.com/actix/actix-web/issues/1501

Some technical limits, a lot of cultural opposition. While it is possible to have a panic handler, it's generally viewed as a bad idea. Not everything is UnwindSafe, there are limits to how much a panic handler can do, concerns about memory leaks.

Again, the caller can turn it into a panic easily enough if that's what they want. leave the decision in their hands.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: