Skip to content

Commit

Permalink
cmd/godoc: remove usage of golang.org/x/xerrors
Browse files Browse the repository at this point in the history
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 <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
  • Loading branch information
findleyr committed Apr 20, 2022
1 parent b22f048 commit 235b13d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/godoc/main.go
Expand Up @@ -21,6 +21,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
_ "expvar" // to serve /debug/vars
"flag"
"fmt"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 235b13d

Please sign in to comment.