I don't know, most of the time, I add information to the error before propagating it:
if f, err := os.Open(path); err != nil {
return nil, fmt.Errorf("could not open path: %v", err)
}
This is the vast majority of my error management code in go. Is rust less verbose in this regard? AFAIK, the question mark operator is equivalent to `if err != nil { return nil, err }`.
Comments
I don't know, most of the time, I add information to the error before propagating it:
This is the vast majority of my error management code in go. Is rust less verbose in this regard? AFAIK, the question mark operator is equivalent to `if err != nil { return nil, err }`.If you want to transform the error on it, you can either:
1. Define a conversion between the two errors that adds the context.
2. Use .map_err() at the callsite to do the transformation there.
Thank you Steve. I'll have a look at map_err().