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 <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>
This commit is contained in:
Robert Findley 2022-04-19 18:42:36 -04:00
Родитель b22f048f6f
Коммит 235b13d9b8
1 изменённых файлов: 4 добавлений и 4 удалений

Просмотреть файл

@ -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