Error chaining with Rust and Go
I was talking with a colleague about Rust and we were wondering (since we are both learning the language) how error handling compares to Go. Chaining error in Go Go’s best practice when you want to chain multiple errors is to “wrap” them. For example let’s say you have this function returning an error: func do_something() err { value := "value" if value != "expected" { return fmt.Errorf("this was not expected") } } when we call the function do_something() from another function, we want to add context to it and to do so we will wrap it around it with the “%w” directive: ...