From 14491a2ec499668388d7fe7e95b84dbf0e1cf04d Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Mon, 13 May 2019 16:46:31 -0700 Subject: fmt: support %w When fmt.Errorf is provided with a %w verb with an error operand, return an error implementing an Unwrap method returning that operand. It is invalid to use %w with other formatting functions, to use %w multiple times in a format string, or to use %w with a non-error operand. When the Errorf format string contains an invalid use of %w, the returned error does not implement Unwrap. Change-Id: I534e20d3b163ab22c2b137b1c9095906dc243221 Reviewed-on: https://go-review.googlesource.com/c/go/+/176998 Reviewed-by: Marcel van Lohuizen --- src/internal/oserror/errors_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/internal/oserror/errors_test.go') diff --git a/src/internal/oserror/errors_test.go b/src/internal/oserror/errors_test.go index 50dd4678d4..6d6a56a0c7 100644 --- a/src/internal/oserror/errors_test.go +++ b/src/internal/oserror/errors_test.go @@ -34,8 +34,7 @@ func TestIsTimeout(t *testing.T) { {true, ttError{timeout: true}}, {true, isError{os.ErrTimeout}}, {true, os.ErrTimeout}, - // TODO: restore when %w is reimplemented - //{true, fmt.Errorf("wrap: %w", os.ErrTimeout)}, + {true, fmt.Errorf("wrap: %w", os.ErrTimeout)}, {false, ttError{timeout: false}}, {false, errors.New("error")}, } { @@ -53,8 +52,7 @@ func TestIsTemporary(t *testing.T) { {true, ttError{temporary: true}}, {true, isError{os.ErrTemporary}}, {true, os.ErrTemporary}, - // TODO: restore when %w is reimplemented - //{true, fmt.Errorf("wrap: %w", os.ErrTemporary)}, + {true, fmt.Errorf("wrap: %w", os.ErrTemporary)}, {false, ttError{temporary: false}}, {false, errors.New("error")}, } { -- cgit v1.3-5-g9baa