@@ -231,8 +231,8 @@ func parseArgs(args []string) (pkg *build.Package, path, symbol string, more boo
231
231
// First, is it a complete package path as it is? If so, we are done.
232
232
// This avoids confusion over package paths that have other
233
233
// package paths as their prefix.
234
- pkg , err = build .Import (arg , wd , build .ImportComment )
235
- if err == nil {
234
+ pkg , importErr : = build .Import (arg , wd , build .ImportComment )
235
+ if importErr == nil {
236
236
return pkg , arg , "" , false
237
237
}
238
238
// Another disambiguator: If the symbol starts with an upper
@@ -286,7 +286,18 @@ func parseArgs(args []string) (pkg *build.Package, path, symbol string, more boo
286
286
}
287
287
// If it has a slash, we've failed.
288
288
if slash >= 0 {
289
- log .Fatalf ("no such package %s" , arg [0 :period ])
289
+ // build.Import should always include the path in its error message,
290
+ // and we should avoid repeating it. Unfortunately, build.Import doesn't
291
+ // return a structured error. That can't easily be fixed, since it
292
+ // invokes 'go list' and returns the error text from the loaded package.
293
+ // TODO(golang.org/issue/34750): load using golang.org/x/tools/go/packages
294
+ // instead of go/build.
295
+ importErrStr := importErr .Error ()
296
+ if strings .Contains (importErrStr , arg [:period ]) {
297
+ log .Fatal (importErrStr )
298
+ } else {
299
+ log .Fatalf ("no such package %s: %s" , arg [:period ], importErrStr )
300
+ }
290
301
}
291
302
// Guess it's a symbol in the current directory.
292
303
return importDir (wd ), "" , arg , false
0 commit comments