• Kirill Smelkov's avatar
    xerr += Context, Contextf · 8f170959
    Kirill Smelkov authored
    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.
    8f170959
xerr.go 2.98 KB