internal/mcp/jsonschema: generalize error wrapping
Add a wrapf function to simplify defers that wrap errors. Change-Id: If4bedec7d3f56f609d3ca4620aebe7637a59f6bf Reviewed-on: https://go-review.googlesource.com/c/tools/+/676475 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
e3938ce68c
commit
4e9d520c2e
1 changed files with 9 additions and 10 deletions
|
|
@ -282,3 +282,10 @@ func assert(cond bool, msg string) {
|
|||
panic("assertion failed: " + msg)
|
||||
}
|
||||
}
|
||||
|
||||
// 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