• Jay Conrod's avatar
    cmd/go: eliminate redundancy in import error messages · 32b6eb80
    Jay Conrod authored
    This change introduces a new interface, load.ImportPathError. An error
    may satisfy this by providing an ImportPath method and including the
    import path in its error text. modload.ImportMissingError satisfies
    this interface. load.ImportErrorf also provides a convenient way to
    create an error satisfying this interface with an arbitrary message.
    
    When load.PackageError formats its error text, it may omit the last
    path on the import stack if the wrapped error satisfies
    ImportPathError and has a matching path.
    
    To make this work, PackageError.Err is now an error instead of a
    string. PackageError.MarshalJSON will write Err as a string for
    'go list -json' output.
    
    When go/build.Import invokes 'go list' in module mode, it now runs
    with '-e' and includes '.Error' in the output format instead of
    expecting the error to be in the raw stderr text. If a package error
    is printed and a directory was not found, the error will be returned
    without extra decoration.
    
    Fixes #34752
    
    Change-Id: I2d81dab7dec19e0ae9f51f6412bc9f30433a8596
    Reviewed-on: https://go-review.googlesource.com/c/go/+/199840
    Run-TryBot: Jay Conrod <jayconrod@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
    32b6eb80
build.go 52.8 KB