vulncheck: add derrors.Wrap to exported functions
Now that x/vuln/vulncheck is not a nested module, we can use the
internal/derrors package to wrap exported functions.
This is a modified CL of https://go-review.googlesource.com/c/exp/+/380134.
Change-Id: I72689511d72cc17f58652d38aca936117fedb2fe
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/395094
Trust: Julie Qiu <julie@golang.org>
Run-TryBot: Julie Qiu <julie@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/vulncheck/binary.go b/vulncheck/binary.go
index 2fcf0ca..b805c8a 100644
--- a/vulncheck/binary.go
+++ b/vulncheck/binary.go
@@ -10,12 +10,15 @@
"runtime"
"golang.org/x/tools/go/packages"
+ "golang.org/x/vuln/internal/derrors"
"golang.org/x/vuln/vulncheck/internal/binscan"
)
// Binary detects presence of vulnerable symbols in exe. The
// imports, require, and call graph are all unavailable (nil).
-func Binary(ctx context.Context, exe io.ReaderAt, cfg *Config) (*Result, error) {
+func Binary(ctx context.Context, exe io.ReaderAt, cfg *Config) (_ *Result, err error) {
+ defer derrors.Wrap(&err, "vulncheck.Binary")
+
mods, packageSymbols, err := binscan.ExtractPackagesAndSymbols(exe)
if err != nil {
return nil, err
diff --git a/vulncheck/source.go b/vulncheck/source.go
index 8b30bce..0d106dd 100644
--- a/vulncheck/source.go
+++ b/vulncheck/source.go
@@ -12,6 +12,7 @@
"golang.org/x/tools/go/callgraph"
"golang.org/x/tools/go/ssa"
+ "golang.org/x/vuln/internal/derrors"
"golang.org/x/vuln/osv"
)
@@ -22,7 +23,8 @@
// package that has some known vulnerabilities
// - call graph leading to the use of a known vulnerable function
// or method
-func Source(ctx context.Context, pkgs []*Package, cfg *Config) (*Result, error) {
+func Source(ctx context.Context, pkgs []*Package, cfg *Config) (_ *Result, err error) {
+ defer derrors.Wrap(&err, "vulncheck.Source")
// buildSSA builds a whole program that assumes all packages use the same FileSet.
// Check all packages in pkgs are using the same FileSet.