• Daniel Martí's avatar
    cmd/doc: print a symbol error on "bytes Foo" · 207c53e0
    Daniel Martí authored
    In golang.org/cl/59413, the two-argument behavior of cmd/doc was changed
    to use findPackage instead of build.Import, meaning that the tool was
    more consistent and useful.
    
    However, it introduced a regression:
    
    	$ go doc bytes Foo
    	doc: no such package: bytes
    
    This is because the directory list search would not find Foo in bytes,
    and reach the end of the directory list - thus resulting in a "no such
    package" error, since no directory matched our first argument.
    
    Move the "no such package" error out of parseArgs, so that the "loop
    until something is printed" loop can have control over it. In
    particular, it is useful to know when we have reached the end of the
    list without any exact match, yet we did find one package matching
    "bytes":
    
    	$ go doc bytes Foo
    	doc: no symbol Foo in package bytes
    
    While at it, make the "no such package" error not be fatal so that we
    may test for it. It is important to have the test, as parseArgs may now
    return a nil package instead of exiting the entire program, potentially
    meaning a nil pointer dereference panic.
    
    Fixes #22810.
    
    Change-Id: I90cc6fd755e2d1675bea6d49a1c13cc18ac9bfb9
    Reviewed-on: https://go-review.googlesource.com/78677
    Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarRob Pike <r@golang.org>
    207c53e0
Name
Last commit
Last update
.github Loading commit data...
api Loading commit data...
doc Loading commit data...
lib/time Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING.md Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README.md Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...