News for hackers. Stuff that matters.
Re:Go’ing Insane: Endless Error Handling by jamespwilliams on Tuesday September 14, 2021 @07:22AM (#28523024)
I haven’t used Rust. Does the ? operator add some kind of stack trace to the error? If not, how do you know where the error has come from?

Having a Result type with statically enforced checking sounds good though.

Re:Go’ing Insane: Endless Error Handling by masklinn on Tuesday September 14, 2021 @09:15AM (#28524286)
> I haven’t used Rust. Does the ? operator add some kind of stack trace to the error?

No. `?` performs an optional conversion and an early return, that’s it (kinda).

> If not, how do you know where the error has come from?

By default you don’t. There are utility libraries you can use to attach such information to error types (and eventually the stdlib will provide one), but OOTB an error value is… quite literally anything (it should probably implement `Error` but doesn’t actually have to).

This is in keeping with the idea that hidden costs should be avoided when possible, and that reified results should be the norm so should have as little requirement as possible.

Re:Go’ing Insane: Endless Error Handling by kevinmgranger on Tuesday September 14, 2021 @10:04AM (#28524995)
> Does the ? operator add some kind of stack trace

It depends. `?` will convert the inner error type (the value from the function to its left) to the outer error type (the return type of the function containing this line). That conversion function can be defined by the inner error type. If the conversion generates a stack trace (or adds to an existing one), then there will be one.

Therefore, "Is there always a stack trace available?" is a tricky question-- it was seen as unimportant during the 1.0 days because they wanted to be able to accommodate low-resource environments.

Today, there's third party error handling libraries that cut out error creation / manipulation boilerplate, that might create stack traces for you, and there's efforts ongoing to see how it might be added to the stdlib.

Re:Go’ing Insane: Endless Error Handling by gilbetron on Tuesday September 14, 2021 @08:58AM (#28524045)
Doing foo()? is equivalent to:

  err := foo()
  if err != nil {
    return err
  }