vulncheck/internal/derrors: add an internal errors package

An internal errors package is added that implements some simple common
error semantics.

derrors.Wrap allows errors to be annotated with a defer statement.

Change-Id: Ief91179f45c6e97856730bd11ed9ee5b8b916312
Reviewed-on: https://go-review.googlesource.com/c/exp/+/359408
Trust: Julie Qiu <julie@golang.org>
Trust: Zvonimir Pavlinovic <zpavlinovic@google.com>
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Zvonimir Pavlinovic <zpavlinovic@google.com>
diff --git a/vulncheck/internal/derrors/derrors.go b/vulncheck/internal/derrors/derrors.go
new file mode 100644
index 0000000..7f1ea9f
--- /dev/null
+++ b/vulncheck/internal/derrors/derrors.go
@@ -0,0 +1,21 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package derrors defines internal error values to categorize the different
+// types error semantics supported by the vulndb.
+package derrors
+
+import "fmt"
+
+// Wrap adds context to the error and allows
+// unwrapping the result to recover the original error.
+//
+// Example:
+//
+// defer derrors.Wrap(&err, "copy(%s, %s)", dst, src)
+func Wrap(errp *error, format string, args ...interface{}) {
+	if *errp != nil {
+		*errp = fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), *errp)
+	}
+}