Skip to content

Commit

Permalink
add Unwrap to VCSError and RunError
Browse files Browse the repository at this point in the history
  • Loading branch information
psampaz committed Sep 10, 2019
1 parent b38be35 commit 22b7108
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cmd/go/internal/modfetch/codehost/codehost.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/cmd/go/internal/modfetch/codehost/codehost_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
2 changes: 2 additions & 0 deletions src/cmd/go/internal/modfetch/codehost/vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)}
}
Expand Down
18 changes: 18 additions & 0 deletions src/cmd/go/internal/modfetch/codehost/vcs_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}

0 comments on commit 22b7108

Please sign in to comment.