Skip to content

Commit

Permalink
all: recognize new error from go command when no go.mod is found
Browse files Browse the repository at this point in the history
This change fixes x/tools tests before CL 298650 lands. After that CL,
the go command reports a different error message when GO111MODULE=on
and it is invoked without a go.mod file (with a command that requires
a go.mod file). We plan to backport that change to 1.16.

For golang/go#44745

Change-Id: Idb3e146828703c89f788ae660ffc95aef16433e4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/298792
Trust: Jay Conrod <jayconrod@google.com>
Reviewed-by: Peter Weinberger <pjw@google.com>
  • Loading branch information
Jay Conrod authored and rinchsan committed May 30, 2021
1 parent 1cde997 commit 1210116
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/imports/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ func (r *ModuleResolver) init() error {
err := r.initAllMods()
// We expect an error when running outside of a module with
// GO111MODULE=on. Other errors are fatal.
if err != nil && !strings.Contains(err.Error(), "working directory is not part of a module") {
return err
if err != nil {
if errMsg := err.Error(); !strings.Contains(errMsg, "working directory is not part of a module") && !strings.Contains(errMsg, "go.mod file not found") {
return err
}
}
}

Expand Down

0 comments on commit 1210116

Please sign in to comment.