internal/mcp/internal/util: add Wrapf
Add Wrapf, a function that helps with error wrapping. Change-Id: I102695f75e4d217e09f828f4723cbfcbbe83f887 Reviewed-on: https://go-review.googlesource.com/c/tools/+/679177 Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Sam Thanawalla <samthanawalla@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
30af200d5e
commit
d9a7859c3b
1 changed files with 17 additions and 20 deletions
|
|
@ -6,6 +6,7 @@ package util
|
|||
|
||||
import (
|
||||
"cmp"
|
||||
"fmt"
|
||||
"iter"
|
||||
"reflect"
|
||||
"slices"
|
||||
|
|
@ -73,3 +74,10 @@ func FieldJSONInfo(f reflect.StructField) JSONInfo {
|
|||
}
|
||||
return info
|
||||
}
|
||||
|
||||
// Wrapf wraps *errp with the given formatted message if *errp is not nil.
|
||||
func Wrapf(errp *error, format string, args ...any) {
|
||||
if *errp != nil {
|
||||
*errp = fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), *errp)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue