Skip to content

Commit

Permalink
cmd/go/internal/module: in VersionError, do not wrap an existing Modu…
Browse files Browse the repository at this point in the history
…leError

VersionError wraps the given error in a ModuleError struct.

If the given error is already a ModuleError for the same path and
version, we now return it directly instead of wrapping.
This makes it safer to call VersionError if we don't know whether
a given error is already wrapped.

Updates #30748

Change-Id: I41b23f6c3ead0ec382e848696da51f478da1ad35
Reviewed-on: https://go-review.googlesource.com/c/go/+/189781
Run-TryBot: Bryan C. Mills <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
Bryan C. Mills committed Sep 12, 2019
1 parent 1581bb9 commit 3d522b1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cmd/go/internal/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ type ModuleError struct {
Err error
}

// VersionError returns a ModuleError derived from a Version and error.
// VersionError returns a ModuleError derived from a Version and error,
// or err itself if it is already such an error.
func VersionError(v Version, err error) error {
var mErr *ModuleError
if errors.As(err, &mErr) && mErr.Path == v.Path && mErr.Version == v.Version {
return err
}
return &ModuleError{
Path: v.Path,
Version: v.Version,
Expand Down

0 comments on commit 3d522b1

Please sign in to comment.