xerr += Context, Contextf
This are handy utilities to automatically prepend context on error return. For example in func myfunc(...) (..., err error) { defer xerr.Context(&err, "error context") ... if ... { return ..., errors.New("an error") } return ..., nil } while preserving nil error return on successful execution, myfunc will return error with string "error context: an error" on failure case.
Showing
Please register or sign in to comment