News for hackers. Stuff that matters.
Re:Tor in a safer language: Network team update from Amsterdam by dullgiulio on Sunday April 02, 2017 @02:13AM (#14016073)
You are not handling the error, you are just returning it.

More correctly, you would decorate the error:

    foo, err := bar()
    if err != nil {
        return nil, fmt.Errorf("failed to do bar: %s", err)
    }
Re:Tor in a safer language: Network team update from Amsterdam by vertex-four on Sunday April 02, 2017 @03:56AM (#14016353)
Sure, in some cases you want to wrap the error type - Rust handles this by essentially having you create a custom error type which is an enum (which can be done via macros like quick-error and error-chain), and implementing From<BarError> on it which'd create your custom error type from the BarError. This trait is used by both the try!() macro and the ? operator (which do much the same thing, the latter being the updated syntax):

    let foo = bar()?;
If you need to do something custom in converting bar()'s error into your error type - which is rare - you can use .map_err() like this:

    let foo = bar().map_err(|e| MyError::BarError(e, extraContext))?;