]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/godoc: don't crash if there's no documentation
authorRobert Griesemer <gri@golang.org>
Thu, 28 Mar 2013 15:46:17 +0000 (08:46 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 28 Mar 2013 15:46:17 +0000 (08:46 -0700)
Fixes regression introduced by CL 7860049.

R=golang-dev, kamil.kisiel, dave
CC=golang-dev
https://golang.org/cl/8069044

src/cmd/godoc/main.go

index ab792c8af06b02b94b3dc2395e06a3eb84a9f701..81e739d20c289a8ded9597451e93307c6ee87b0a 100644 (file)
@@ -388,12 +388,12 @@ func main() {
        }
 
        // determine what to use
-       if info.IsEmpty() {
-               if !cinfo.IsEmpty() {
+       if info == nil || info.IsEmpty() {
+               if cinfo != nil && !cinfo.IsEmpty() {
                        // only cinfo exists - switch to cinfo
                        info = cinfo
                }
-       } else if !cinfo.IsEmpty() {
+       } else if cinfo != nil && !cinfo.IsEmpty() {
                // both info and cinfo exist - use cinfo if info
                // contains only subdirectory information
                if info.PAst == nil && info.PDoc == nil {
@@ -403,9 +403,13 @@ func main() {
                }
        }
 
+       if info == nil {
+               log.Fatalf("%s: no such directory or package", flag.Arg(0))
+       }
        if info.Err != nil {
                log.Fatalf("%v", info.Err)
        }
+
        if info.PDoc != nil && info.PDoc.ImportPath == target {
                // Replace virtual /target with actual argument from command line.
                info.PDoc.ImportPath = flag.Arg(0)