github.com/glimps-jbo/go-licenses@v0.0.0-20230908151000-e06d3c113277/internal/third_party/pkgsite/derrors/derrors.go (about) 1 // Copyright 2019 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 we support. 7 package derrors 8 9 import ( 10 "errors" 11 "fmt" 12 ) 13 14 //lint:file-ignore ST1012 prefixing error values with Err would stutter 15 16 var ( 17 // NotFound indicates that a requested entity was not found (HTTP 404). 18 NotFound = errors.New("not found") 19 20 // InvalidArgument indicates that the input into the request is invalid in 21 // some way (HTTP 400). 22 InvalidArgument = errors.New("invalid argument") 23 ) 24 25 // Wrap adds context to the error and allows 26 // unwrapping the result to recover the original error. 27 // 28 // Example: 29 // 30 // defer derrors.Wrap(&err, "copy(%s, %s)", src, dst) 31 // 32 // See Add for an equivalent function that does not allow 33 // the result to be unwrapped. 34 func Wrap(errp *error, format string, args ...any) { 35 if *errp != nil { 36 *errp = fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), *errp) 37 } 38 }