diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go index 5e5bc225..9e704692 100644 --- a/cmd/godoc/main.go +++ b/cmd/godoc/main.go @@ -356,6 +356,7 @@ func main() { return } + build.Default.GOROOT = *goroot if err := godoc.CommandLine(os.Stdout, fs, pres, flag.Args()); err != nil { log.Print(err) } diff --git a/godoc/cmdline.go b/godoc/cmdline.go index b531b4df..86861593 100644 --- a/godoc/cmdline.go +++ b/godoc/cmdline.go @@ -134,18 +134,25 @@ func CommandLine(w io.Writer, fs vfs.NameSpace, pres *Presentation, args []strin // for this. That is, if we get passed a directory like the above, we map that // directory so that getPageInfo sees it as /target. // Returns the absolute and relative paths. -func paths(fs vfs.NameSpace, pres *Presentation, path string) (string, string) { +func paths(fs vfs.NameSpace, pres *Presentation, path string) (abspath, relpath string) { if filepath.IsAbs(path) { fs.Bind(target, vfs.OS(path), "/", vfs.BindReplace) return target, target } if build.IsLocalImport(path) { - cwd, _ := os.Getwd() // ignore errors + cwd, err := os.Getwd() + if err != nil { + log.Printf("error while getting working directory: %v", err) + } path = filepath.Join(cwd, path) fs.Bind(target, vfs.OS(path), "/", vfs.BindReplace) return target, target } - if bp, _ := build.Import(path, "", build.FindOnly); bp.Dir != "" && bp.ImportPath != "" { + bp, err := build.Import(path, "", build.FindOnly) + if err != nil { + log.Printf("error while importing build package: %v", err) + } + if bp.Dir != "" && bp.ImportPath != "" { fs.Bind(target, vfs.OS(bp.Dir), "/", vfs.BindReplace) return target, bp.ImportPath }