@@ -28,6 +28,7 @@ import (
28
28
type ImportMissingError struct {
29
29
ImportPath string
30
30
Module module.Version
31
+ QueryErr error
31
32
32
33
// newMissingVersion is set to a newer version of Module if one is present
33
34
// in the build list. When set, we can't automatically upgrade.
@@ -39,9 +40,12 @@ func (e *ImportMissingError) Error() string {
39
40
if str .HasPathPrefix (e .ImportPath , "cmd" ) {
40
41
return fmt .Sprintf ("package %s is not in GOROOT (%s)" , e .ImportPath , filepath .Join (cfg .GOROOT , "src" , e .ImportPath ))
41
42
}
43
+ if e .QueryErr != nil {
44
+ return fmt .Sprintf ("cannot find module providing package %s: %v" , e .ImportPath , e .QueryErr )
45
+ }
42
46
return "cannot find module providing package " + e .ImportPath
43
47
}
44
- return "missing module for import: " + e .Module .Path + "@" + e .Module .Version + " provides " + e .ImportPath
48
+ return fmt . Sprintf ( "missing module for import: %s@%s provides %s" , e .Module .Path , e .Module .Version , e .ImportPath )
45
49
}
46
50
47
51
// Import finds the module and directory in the build list
@@ -197,7 +201,7 @@ func Import(path string) (m module.Version, dir string, err error) {
197
201
if errors .Is (err , os .ErrNotExist ) {
198
202
// Return "cannot find module providing package […]" instead of whatever
199
203
// low-level error QueryPackage produced.
200
- return module.Version {}, "" , & ImportMissingError {ImportPath : path }
204
+ return module.Version {}, "" , & ImportMissingError {ImportPath : path , QueryErr : err }
201
205
} else {
202
206
return module.Version {}, "" , err
203
207
}
0 commit comments