Live data from Hacker News

Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

msirringhaus.github.io

181–190 of 204 posts

Re: Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

#181
post #55
post #17

Someday I will attempt to use some rust software from the internet without almost immediately running into a panic with some inscrutable message. Maybe that day will be a day after _f$#$@@#$_ _crashing_ stops being the easiest and most idiomatic way of handling unexpected conditions.

I prefer it when a program just gives up and crashes when it encounters an unexpected condition, instead of trying to soldier on and later possibly corrupting some data or state I care about, because it was working under incorrect assumptions. Now, the amount of unexpected conditions should be kept to a minimum, essentially just things outside of control of that program that the program cannot verify reliably. The re…

In C applications people will generally fprintf(stderr, "Froboz option requires a grimulax!\n");exit(EXIT_FAILURE); Which is pretty useful.

In rust, my experience is that it's far more common to unwrap an empty result and just toss a panic which spams some almost completely inscrutable error at the user.

I'm not sure what the cause is-- it's been suggested to me by a heavy duty rust user that part of it is norms for library code (where exiting-as-error-handling would not be very welcome) and applied them to the whole ecosystem.

I've also been told that it's not uncommon for people to use library code for handling stuff that would be manually written in C but then the library code under-documents what the failure cases are and so the caller can't easily/obviously do anything more than panic on an empty result.

Whatever the cause the end result is that literally every single program I pull off github written in rust I encounter some panic. In fact, as of a about a month ago even firefox started regularly crashing for me w/ some panic in servo (triggered by twitter).

The majority of the panics I get from stuff are just trivial "You used the wrong command-line options", but it's hard to resist the impression that software written in rust is simply a lot lower quality. It might well be that some of this is software that wouldn't even have been published had it been attempted in C, or that it's just because a greater percentage is written by developers who are new to programming (or at least new to systems programming)... but that isn't observable.

The net result though is that it leaves me feeling uneasy and dubious about the claims of rust lowering defect rates, especially since there has been no formal validation of those beliefs. It sounds credible for sure, but if rust is freeing up programmers to worry about things other than memory safety, it's not showing from my experience. You can go back 5 years in my history and see that I promoted rust a lot -- I even opted for my former company to use it. But that was before encountering other people's rust code in practice.

I think for years java suffered greatly from similar bad impressions-- where you don't expect to be able to run something you found without dealing with a maze of inscrutable null pointer exceptions.

Re: Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

#182
post #9

Earlier quoted context omitted.

The only system I think should completely go is Exceptions except in the case of termination or absolutely catastrophic failure - this isn't really about programming but rather that the implementation is a total pain, the compiler struggles to optimize them, and even better they make quite a few safety analyses like borrow checking very difficult because the control flow graph basically explodes when you start consid…

> the compiler struggles to optimize them, Nitpick: I'd say if you need the compiler to optimize exception handling you are using them wrong. Exceptions are for exceptional circumstances. (if you mean that exceptions mess up optimization of surrounding code that could be a bigger deal but I won't accept that without pointers to benchmarks$

Exceptions force a less efficient ABI, for example - take a look at unique_ptr, it should be in a register but it's not.

Re: Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

#183

Earlier quoted context omitted.

> I don't really understand this criticism, because there's no good alternative. There's the option of surfacing the panic-ability of a function in the same way the constness is surfaced, which would allow some subsets of the code to ensure they won't call a possibly-panicing thing, even at the cost of convenience.

In the cases where the problem is actually panicing (ie, a non-total function) rather than your choice of core-dumping code, lack of panic-ability is strictly insufficient - `while(1){/*busy-loop*/}` is exactly as bad as `panic();`, and what you actually need is not "must never panic", it's "must make forward progress within some (not necessarily rigorously defined but) small amount of time". That doesn't have anythi…

> lack of panic-ability is strictly insufficient

Sure. It is also by far the largest risk you face, so would solve a good 4 or 5 nines if the issue.

> And really, noreturn ought to be enough to infer that on its own.

noreturn only works for functions which never return. Most panicking functions do return, just not all the time.

Re: Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

#184

Error handling has been wrong since the beginning, and has continued to be wrong ever since. First, we had error codes. Except these were wrong because people forget all the time to check them. Then we had exceptions, which solved the problem of people forgetting to check by crashing the app. Then the Java team got the bright idea to have checked exceptions, which at first helped to mitigate crashes from uncaught exc…

> Then the Java team got the bright idea to have checked exceptions

The Java team adopted the ideas of CLU, Modula-3 and C++, yet it keeps getting the blame while being the fourth language implementing the idea.

Re: Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

#185

Error handling has been wrong since the beginning, and has continued to be wrong ever since. First, we had error codes. Except these were wrong because people forget all the time to check them. Then we had exceptions, which solved the problem of people forgetting to check by crashing the app. Then the Java team got the bright idea to have checked exceptions, which at first helped to mitigate crashes from uncaught exc…

> Then we had exceptions, which solved the problem of people forgetting to check by crashing the app. They can also harm readability, as just about every statement can now cause an early return from a block. They also greatly complicate static analysis. No discussion of the shortcomings of conventional exceptions would be complete without these two excellent blog posts by the great Raymond Chen: Cleaner, more elegant…

The only programming language where exceptions are such a problem is C++.

First of all, because a religious subculture will run to pitchforks and torches at the slight mention of the word exceptions in the room.

Then the overall machinery in place to make them work alongside code that was most likely written as C originally.

And naturally every ms and byte lost to exceptions infrastructure is a capital felony, so even more fine grained semantics to make it happen.

C++ is still the language I reach for when not doing any JVM/.NET language, but things like this is what takes the fun out of using it with another ones on a team.

Re: Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

#186

Earlier quoted context omitted.

I've found the rust debugging experience to be very primative. When you say modern tools, are you describing rr? As far as I know that doesn't reliably integrate with rust?

I've used gdb just fine on Rust code. Pretty printing isn't always as good, but if Rust is crashing, I'm probably down towards the syscall level anyways (or blowing the stack size as my last observed crashes were triggering).

I've had similar experiences. Inwas referring to the parent arguing that using Results and error enums to debug your own code is silly when you could just step backwards in a debugger. In my experience the rust debugging story isn't fluid enough that it's better than logging to debug most logic bugs.

Re: Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

#187
post #185

Earlier quoted context omitted.

> Then we had exceptions, which solved the problem of people forgetting to check by crashing the app. They can also harm readability, as just about every statement can now cause an early return from a block. They also greatly complicate static analysis. No discussion of the shortcomings of conventional exceptions would be complete without these two excellent blog posts by the great Raymond Chen: Cleaner, more elegant…

The only programming language where exceptions are such a problem is C++. First of all, because a religious subculture will run to pitchforks and torches at the slight mention of the word exceptions in the room. Then the overall machinery in place to make them work alongside code that was most likely written as C originally. And naturally every ms and byte lost to exceptions infrastructure is a capital felony, so eve…

> The only programming language where exceptions are such a problem is C++.

I'm not sure what you mean here, neither article is about the low-level issues that arise in C++. The second article only discusses C#. Chen's point is more about the way every call can surprise you by causing your code to return early.

Re: Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

#188
post #179

Earlier quoted context omitted.

> Error handling has been wrong since the beginning 100% this. The very concept of "error" is philosophically unsound. There are no errors; only conditions that you dislike. It is unfortunate that programming languages allow to express your emotional detachment to one of both cases of a branch. Nothing good can come from that. I yearn for a language with no error handling nor exceptions. Just plain language construct…

I'm confused. Isn't that just C? There's no errors in C, or exceptions. The only exceptions are interrupts/signals, but those aren't part of the language, but the machine or OS.

there's nothing to be confused about, C is one of the few languages that gets it right (the base language... the stdlib is a different story)

Re: Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

#189
post #185

Earlier quoted context omitted.

The only programming language where exceptions are such a problem is C++. First of all, because a religious subculture will run to pitchforks and torches at the slight mention of the word exceptions in the room. Then the overall machinery in place to make them work alongside code that was most likely written as C originally. And naturally every ms and byte lost to exceptions infrastructure is a capital felony, so eve…

> The only programming language where exceptions are such a problem is C++. I'm not sure what you mean here, neither article is about the low-level issues that arise in C++. The second article only discusses C#. Chen's point is more about the way every call can surprise you by causing your code to return early.

EINTR and longjmp can also surprise you, even in middle of calls, yet C doesn't have any exceptions.

Re: Where Everything Went Wrong: Error Handling and Error Messages in Rust (2020)

#190
post #189

Earlier quoted context omitted.

> The only programming language where exceptions are such a problem is C++. I'm not sure what you mean here, neither article is about the low-level issues that arise in C++. The second article only discusses C#. Chen's point is more about the way every call can surprise you by causing your code to return early.

EINTR and longjmp can also surprise you, even in middle of calls, yet C doesn't have any exceptions.

You're right that the C language has many weird and wonderful capabilities and footguns. How does that address Chen's point about exceptions being unmanageable?
Post reply on HN