From 235b13d9b800c5bd5ec07c006b7bfbb624b14429 Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Tue, 19 Apr 2022 18:42:36 -0400 Subject: [PATCH] cmd/godoc: remove usage of golang.org/x/xerrors Go 1.12 has not been supported for a while, so it seems safe to replace usage of xerrors with the native support for wrapped errors in the standard library introduced in Go 1.13. Remove this usage as a step toward eliminating the xerrors dependency from x/tools. If there is any reason to continue to use xerrors, please let me know. For golang/go#52442 Change-Id: Ic1e5c14f4074b4685a926e884649b9032aaa0f53 Reviewed-on: https://go-review.googlesource.com/c/tools/+/401098 Run-TryBot: Robert Findley gopls-CI: kokoro TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- cmd/godoc/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go index fc223684b48..79dcf38210a 100644 --- a/cmd/godoc/main.go +++ b/cmd/godoc/main.go @@ -21,6 +21,7 @@ import ( "bytes" "context" "encoding/json" + "errors" _ "expvar" // to serve /debug/vars "flag" "fmt" @@ -46,7 +47,6 @@ import ( "golang.org/x/tools/godoc/vfs/mapfs" "golang.org/x/tools/godoc/vfs/zipfs" "golang.org/x/tools/internal/gocommand" - "golang.org/x/xerrors" ) const defaultAddr = "localhost:6060" // default webserver address @@ -372,7 +372,7 @@ func main() { // or the empty string if not using modules. func goMod() (string, error) { out, err := exec.Command("go", "env", "-json", "GOMOD").Output() - if ee := (*exec.ExitError)(nil); xerrors.As(err, &ee) { + if ee := (*exec.ExitError)(nil); errors.As(err, &ee) { return "", fmt.Errorf("go command exited unsuccessfully: %v\n%s", ee.ProcessState.String(), ee.Stderr) } else if err != nil { return "", err @@ -405,7 +405,7 @@ func fillModuleCache(w io.Writer, goMod string) { cmd.Stdout = &out cmd.Stderr = w err := cmd.Run() - if ee := (*exec.ExitError)(nil); xerrors.As(err, &ee) && ee.ExitCode() == 1 { + if ee := (*exec.ExitError)(nil); errors.As(err, &ee) && ee.ExitCode() == 1 { // Exit code 1 from this command means there were some // non-empty Error values in the output. Print them to w. fmt.Fprintf(w, "documentation for some packages is not shown:\n") @@ -449,7 +449,7 @@ func buildList(goMod string) ([]mod, error) { } out, err := exec.Command("go", "list", "-m", "-json", "all").Output() - if ee := (*exec.ExitError)(nil); xerrors.As(err, &ee) { + if ee := (*exec.ExitError)(nil); errors.As(err, &ee) { return nil, fmt.Errorf("go command exited unsuccessfully: %v\n%s", ee.ProcessState.String(), ee.Stderr) } else if err != nil { return nil, err