derrors.go (645B)
1 // Copyright 2021 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package derrors defines internal error values to categorize the different 6 // types error semantics supported by x/vuln. 7 package derrors 8 9 import ( 10 "fmt" 11 ) 12 13 // Wrap adds context to the error and allows 14 // unwrapping the result to recover the original error. 15 // 16 // Example: 17 // 18 // defer derrors.Wrap(&err, "copy(%s, %s)", dst, src) 19 func Wrap(errp *error, format string, args ...interface{}) { 20 if *errp != nil { 21 *errp = fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), *errp) 22 } 23 }