From 22b7108b87acc29de61b998b9be525536c7f30a8 Mon Sep 17 00:00:00 2001 From: Pantelis Sampaziotis Date: Tue, 10 Sep 2019 22:17:49 +0300 Subject: [PATCH] add Unwrap to VCSError and RunError --- .../go/internal/modfetch/codehost/codehost.go | 2 ++ .../modfetch/codehost/codehost_test.go | 18 ++++++++++++++++++ src/cmd/go/internal/modfetch/codehost/vcs.go | 2 ++ .../go/internal/modfetch/codehost/vcs_test.go | 18 ++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 src/cmd/go/internal/modfetch/codehost/codehost_test.go create mode 100644 src/cmd/go/internal/modfetch/codehost/vcs_test.go diff --git a/src/cmd/go/internal/modfetch/codehost/codehost.go b/src/cmd/go/internal/modfetch/codehost/codehost.go index a4e50d692a329c..c8f8536e32598a 100644 --- a/src/cmd/go/internal/modfetch/codehost/codehost.go +++ b/src/cmd/go/internal/modfetch/codehost/codehost.go @@ -242,6 +242,8 @@ func (e *RunError) Error() string { return text } +func (e *RunError) Unwrap() error { return e.Err } + var dirLock sync.Map // Run runs the command line in the given directory diff --git a/src/cmd/go/internal/modfetch/codehost/codehost_test.go b/src/cmd/go/internal/modfetch/codehost/codehost_test.go new file mode 100644 index 00000000000000..b3a1c104ceb1f4 --- /dev/null +++ b/src/cmd/go/internal/modfetch/codehost/codehost_test.go @@ -0,0 +1,18 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package codehost + +import ( + "errors" + "testing" +) + +func TestRunErrorUnwrap(t *testing.T) { + werr := errors.New("wrapped error") + err := &RunError{Err: werr} + if !errors.Is(err, werr) { + t.Error("errors.Is failed, wanted success") + } +} diff --git a/src/cmd/go/internal/modfetch/codehost/vcs.go b/src/cmd/go/internal/modfetch/codehost/vcs.go index 48238f176c6dae..ada89979b7aca8 100644 --- a/src/cmd/go/internal/modfetch/codehost/vcs.go +++ b/src/cmd/go/internal/modfetch/codehost/vcs.go @@ -38,6 +38,8 @@ type VCSError struct { func (e *VCSError) Error() string { return e.Err.Error() } +func (e *VCSError) Unwrap() error { return e.Err } + func vcsErrorf(format string, a ...interface{}) error { return &VCSError{Err: fmt.Errorf(format, a...)} } diff --git a/src/cmd/go/internal/modfetch/codehost/vcs_test.go b/src/cmd/go/internal/modfetch/codehost/vcs_test.go new file mode 100644 index 00000000000000..8205887232bc62 --- /dev/null +++ b/src/cmd/go/internal/modfetch/codehost/vcs_test.go @@ -0,0 +1,18 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package codehost + +import ( + "errors" + "testing" +) + +func TestVCSErrorUnwrap(t *testing.T) { + werr := errors.New("wrapped error") + err := &VCSError{Err: werr} + if !errors.Is(err, werr) { + t.Error("errors.Is failed, wanted success") + } +}