go/packages: fix support for ad-hoc packages to handle errors
This change retries the query even if go/packages returns an error, not just an empty response. This also fixes support for ad-hoc packages in gopls. Change-Id: I7bc07c225568efd18f4e5759f7eb3c23cd12bfa4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/182580 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
parent
6fea9ef05e
commit
1d40570c5c
|
@ -229,12 +229,11 @@ func runContainsQueries(cfg *Config, driver driver, response *responseDeduper, q
|
||||||
}
|
}
|
||||||
dirResponse, err := driver(cfg, pattern)
|
dirResponse, err := driver(cfg, pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
if len(dirResponse.Roots) == 0 {
|
|
||||||
// Couldn't find a package for the directory. Try to load the file as an ad-hoc package.
|
// Couldn't find a package for the directory. Try to load the file as an ad-hoc package.
|
||||||
|
var queryErr error
|
||||||
dirResponse, err = driver(cfg, query)
|
dirResponse, err = driver(cfg, query)
|
||||||
if err != nil {
|
if queryErr != nil {
|
||||||
|
// Return the original error if the attempt to fall back failed.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue