4 ms·
The output of panic! seems to be useful only to the programmer, not the user. As a user, getting an error message like that would lead me to think that the appl
by Sharlin 10y ago
The output of panic! seems to be useful only to the programmer, not the user. As a user, getting an error message like that would lead me to think that the application is defective, as it arguably is if it cannot provide better user experience in a completely expected error condition like a port being already in use.
- steveklabnik 10y agoAbsolutely. Your users aren't likely to be seeing a server-side process like this fail, though, so in this situation, seems fine. As I said in the post you're replying to, a nicer error message would be a good thing.
- Sharlin 10y ago> Your users aren't likely to be seeing a server-side process like this fail, though, so in this situation, seems fine. Whoever maintains the server and runs the service is also my user, though, in the general case. > As I said in the post you're replying to, a nicer error message would be a good thing. Yeah - I don't mind if unwrap panics with a dev-oriented message as it's basically an assertion, but I guess I expected expect() (no pun intended) to give a more user-friendly error. Maybe the format of the panic! output could be changed to bring the message to the front and the technical details after that.
- sidlls 10y agoIn the world of server systems programming once an organization gets beyond a certain size it's uncommon to have programmers administering server daemons or other server applications. Those folks are indeed users.
- kibwen 10y agoSee my sibling comment to the above. By the time your software has matured enough that it's been deployed to non-developers, unwraps have no place in the code. It's not an error-handling strategy, it's just "// TODO: Add error handling" that the compiler understands.
- contras1970 10y agoExample code should be exemplary.
- steveklabnik 10y agoAs I said elsewhere, exemplary of what? The concept, or robust error handling? Even with the latter, it's unclear what the _right_ error handling is without knowing what you're actually doing.
- kibwen 10y agoThe output of panic will only ever be seen by the programmer. Unwrap exists to ease prototyping and to make simple code examples. IME, the first thing you do when you take a Rust application from the prototype phase to the production phase is to grep for unwraps and insert proper error handling.
- p0nce 10y ago> The output of panic will only ever be seen by the programmer. Obviously not if it's used for input errors (network failure). Crashing assertions are made for bugs, not input errors.
- kibwen 10y agoPlease read the rest of my comment. It's not used for input errors.
- p0nce 10y agoThis is invalid since nothing in the compiler forces you to remove the .unwrap() so it's safe to assume it will not be done before production. The whole "but this is just for prototyping" is a logical fallacy, as you know we have tons of prototypes in production ;)
- kibwen 10y agoI admit that I'm having a hard time seeing this criticism as anything but overblown. Finding usage of unwrap is trivially easy via textual search. Furthermore, Clippy can be used to automatically forbid usage of unwrap for your entire team ( https://github.com/Manishearth/rust-clippy/wiki#option_unwrap_used https://github.com/Manishearth/rust-clippy/wiki#option_unwra... ). Furthermore, even when you hit a panic, it tells you which line of code in which file triggered it so that you can fix it immediately. Furthermore, the Rust community has a strong and long-entrenched proscription against libraries which unwrap rather than handle errors. We can agree in the cynical interpretation of the laziness of programmers, but the mitigations in this case are so trivial, and the stakes so low, that focusing on unwrap as a point of contention is a poor use of energy.