Chore: Drop xerrors dependency (#26718)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2020-07-31 09:45:20 +02:00
committed by GitHub
parent 5a6afd9096
commit 16c185c3b9
20 changed files with 79 additions and 61 deletions
+3 -8
View File
@@ -2,23 +2,18 @@ package errutil
import (
"fmt"
"golang.org/x/xerrors"
)
// Wrap is a simple wrapper around Errorf that is doing error wrapping. You can read how that works in
// https://godoc.org/golang.org/x/xerrors#Errorf but its API is very implicit which is a reason for this wrapper.
// There is also a discussion (https://github.com/golang/go/issues/29934) where many comments make arguments for such
// wrapper so hopefully it will be added in the standard lib later.
// Wrap is a simple wrapper around fmt.Errorf that wraps errors.
func Wrap(message string, err error) error {
if err == nil {
return nil
}
return xerrors.Errorf("%v: %w", message, err)
return fmt.Errorf("%v: %w", message, err)
}
// Wrapf is a simple wrapper around Errorf that is doing error wrapping
// Wrapf is a simple wrapper around fmt.Errorf that wraps errors.
// Wrapf allows you to send a format and args instead of just a message.
func Wrapf(err error, message string, a ...interface{}) error {
if err == nil {
+1 -1
View File
@@ -12,7 +12,7 @@ import (
func ParseIPAddress(input string) (string, error) {
addr, err := SplitHostPort(input)
if err != nil {
return "", errutil.Wrapf(err, "Failed to split network address '%s' by host and port",
return "", errutil.Wrapf(err, "failed to split network address %q by host and port",
input)
}
+7 -7
View File
@@ -1,10 +1,10 @@
package util
import (
"fmt"
"testing"
. "github.com/smartystreets/goconvey/convey"
"golang.org/x/xerrors"
)
func TestParseIPAddress(t *testing.T) {
@@ -28,16 +28,16 @@ func TestParseIPAddress(t *testing.T) {
Convey("Invalid address", t, func() {
_, err := ParseIPAddress("[::1")
So(err, ShouldBeError, xerrors.Errorf(
"Failed to split network address '[::1' by host and port: Malformed IPv6 address: '[::1'"))
So(err, ShouldBeError, fmt.Errorf(
`failed to split network address "[::1" by host and port: Malformed IPv6 address: '[::1'`))
_, err = ParseIPAddress("::1]")
So(err, ShouldBeError, xerrors.Errorf(
"Failed to split network address '::1]' by host and port: net.SplitHostPort failed for '::1]': address ::1]: too many colons in address"))
So(err, ShouldBeError, fmt.Errorf(
`failed to split network address "::1]" by host and port: net.SplitHostPort failed for '::1]': address ::1]: too many colons in address`))
_, err = ParseIPAddress("")
So(err, ShouldBeError, xerrors.Errorf(
"Failed to split network address '' by host and port: Input is empty"))
So(err, ShouldBeError, fmt.Errorf(
`failed to split network address "" by host and port: Input is empty`))
})
Convey("Loopback address", t, func() {