diff options
author | Bryan C. Mills <bcmills@google.com> | 2019-12-20 09:34:30 -0500 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2019-12-20 15:33:31 +0000 |
commit | 82575285913b8b3d7257b21fd33b3226e78e5320 (patch) | |
tree | 55cad830ff7527755e60dcc4d58c4be4b43c9638 /src/cmd/go/internal/modload/load.go | |
parent | 751aea8f199fdc9b0cbacf4fdd554bead8dbfdb9 (diff) | |
download | go-82575285913b8b3d7257b21fd33b3226e78e5320.tar.gz go-82575285913b8b3d7257b21fd33b3226e78e5320.zip |
cmd/go: diagnose missing replacement directories
I noticed the missing diagnostic when writing a regression test for #33795.
Change-Id: Ic3249436a6109d71f9ff720b7096f9b872f6a94b
Reviewed-on: https://go-review.googlesource.com/c/go/+/212201
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r-- | src/cmd/go/internal/modload/load.go | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index 2df7bd04b7..58e2141f65 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -1320,6 +1320,21 @@ func fetch(mod module.Version) (dir string, isLocal bool, err error) { if !filepath.IsAbs(dir) { dir = filepath.Join(ModRoot(), dir) } + // Ensure that the replacement directory actually exists: + // dirInModule does not report errors for missing modules, + // so if we don't report the error now, later failures will be + // very mysterious. + if _, err := os.Stat(dir); err != nil { + if os.IsNotExist(err) { + // Semantically the module version itself “exists” — we just don't + // have its source code. Remove the equivalence to os.ErrNotExist, + // and make the message more concise while we're at it. + err = fmt.Errorf("replacement directory %s does not exist", r.Path) + } else { + err = fmt.Errorf("replacement directory %s: %w", r.Path, err) + } + return dir, true, module.VersionError(mod, err) + } return dir, true, nil } mod = r |