Skip to content

Commit

Permalink
xerrors: use any [generated]
Browse files Browse the repository at this point in the history
[git-generate]
gofmt -r 'interface{} -> any' -w .

Change-Id: I2ea2c800cd1485d57535f3b1446be728e8f5c2dd
Reviewed-on: https://go-review.googlesource.com/c/xerrors/+/610076
LUCI-TryBot-Result: Go LUCI <[email protected]>
Auto-Submit: Dmitri Shuralyov <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
dmitshur authored and gopherbot committed Sep 3, 2024
1 parent cf14814 commit 0c47e2b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ func (s *state) Write(b []byte) (n int, err error) {
// printer wraps a state to implement an xerrors.Printer.
type printer state

func (s *printer) Print(args ...interface{}) {
func (s *printer) Print(args ...any) {
if !s.inDetail || s.printDetail {
fmt.Fprint((*state)(s), args...)
}
}

func (s *printer) Printf(format string, args ...interface{}) {
func (s *printer) Printf(format string, args ...any) {
if !s.inDetail || s.printDetail {
fmt.Fprintf((*state)(s), format, args...)
}
Expand Down
4 changes: 2 additions & 2 deletions fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const percentBangString = "%!"
//
// Note that as of Go 1.13, the fmt.Errorf function will do error formatting,
// but it will not capture a stack backtrace.
func Errorf(format string, a ...interface{}) error {
func Errorf(format string, a ...any) error {
format = formatPlusW(format)
// Support a ": %[wsv]" suffix, which works well with xerrors.Formatter.
wrap := strings.HasSuffix(format, ": %w")
Expand Down Expand Up @@ -81,7 +81,7 @@ func Errorf(format string, a ...interface{}) error {
return &wrapError{msg, err, frame}
}

func errorAt(args []interface{}, i int) error {
func errorAt(args []any, i int) error {
if i < 0 || i >= len(args) {
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions fmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,10 @@ func (e formatError) GoString() string {

type fmtTwiceErr struct {
format string
args []interface{}
args []any
}

func fmtTwice(format string, a ...interface{}) error {
func fmtTwice(format string, a ...any) error {
return fmtTwiceErr{format, a}
}

Expand Down Expand Up @@ -588,11 +588,11 @@ type testPrinter struct {
str string
}

func (p *testPrinter) Print(a ...interface{}) {
func (p *testPrinter) Print(a ...any) {
p.str += fmt.Sprint(a...)
}

func (p *testPrinter) Printf(format string, a ...interface{}) {
func (p *testPrinter) Printf(format string, a ...any) {
p.str += fmt.Sprintf(format, a...)
}

Expand Down
4 changes: 2 additions & 2 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ type Formatter interface {
// typically provide their own implementations.
type Printer interface {
// Print appends args to the message output.
Print(args ...interface{})
Print(args ...any)

// Printf writes a formatted string.
Printf(format string, args ...interface{})
Printf(format string, args ...any)

// Detail reports whether error detail is requested.
// After the first call to Detail, all text written to the Printer
Expand Down
4 changes: 2 additions & 2 deletions stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ func BenchmarkErrorf(b *testing.B) {
err := xerrors.New("foo")
// pi := big.NewFloat(3.14) // Something expensive.
num := big.NewInt(5)
args := func(a ...interface{}) []interface{} { return a }
args := func(a ...any) []any { return a }
benchCases := []struct {
name string
format string
args []interface{}
args []any
}{
{"no_format", "msg: %v", args(err)},
{"with_format", "failed %d times: %v", args(5, err)},
Expand Down
4 changes: 2 additions & 2 deletions wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Is(err, target error) bool {
// matches the type to which target points.
//
// Deprecated: As of Go 1.13, use errors.As instead.
func As(err error, target interface{}) bool {
func As(err error, target any) bool {
if target == nil {
panic("errors: target cannot be nil")
}
Expand All @@ -101,7 +101,7 @@ func As(err error, target interface{}) bool {
val.Elem().Set(reflect.ValueOf(err))
return true
}
if x, ok := err.(interface{ As(interface{}) bool }); ok && x.As(target) {
if x, ok := err.(interface{ As(any) bool }); ok && x.As(target) {
return true
}
err = Unwrap(err)
Expand Down
6 changes: 3 additions & 3 deletions wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type poser struct {

func (p *poser) Error() string { return p.msg }
func (p *poser) Is(err error) bool { return p.f(err) }
func (p *poser) As(err interface{}) bool {
func (p *poser) As(err any) bool {
switch x := err.(type) {
case **poser:
*x = p
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestAs(t *testing.T) {

testCases := []struct {
err error
target interface{}
target any
match bool
}{{
nil,
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestAs(t *testing.T) {

func TestAsValidation(t *testing.T) {
var s string
testCases := []interface{}{
testCases := []any{
nil,
(*int)(nil),
"error",
Expand Down

0 comments on commit 0c47e2b

Please sign in to comment.