internal/fetchdatasource: ignore latest-version errors
A FetchDataSource may be configured with a proxy for latest-version
information while still being used for local modules. So ignore
latest-version errors.
For golang/go#47780
Change-Id: I30448e133faec80002194df59e6f2db449f80625
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/345249
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/internal/fetchdatasource/fetchdatasource.go b/internal/fetchdatasource/fetchdatasource.go
index 896899d..69f803e 100644
--- a/internal/fetchdatasource/fetchdatasource.go
+++ b/internal/fetchdatasource/fetchdatasource.go
@@ -103,16 +103,15 @@
m, err := ds.fetch(ctx, modulePath, version)
if m != nil && ds.opts.ProxyClientForLatest != nil {
// Use the go.mod file at the raw latest version to fill in deprecation
- // and retraction information.
- lmv, err2 := fetch.LatestModuleVersions(ctx, modulePath, ds.opts.ProxyClientForLatest, nil)
- if err2 != nil {
- err = err2
- } else {
+ // and retraction information. Ignore any problems getting the
+ // information, because we may be trying to do this for a local module
+ // that the proxy doesn't know about.
+ if lmv, err := fetch.LatestModuleVersions(ctx, modulePath, ds.opts.ProxyClientForLatest, nil); err == nil {
lmv.PopulateModuleInfo(&m.ModuleInfo)
}
}
- // Don't cache cancellations.
+ // Cache both successes and failures, but not cancellations.
if !errors.Is(err, context.Canceled) {
ds.cachePut(modulePath, version, m, err)
}
diff --git a/internal/fetchdatasource/fetchdatasource_test.go b/internal/fetchdatasource/fetchdatasource_test.go
index c95ee2a..a1fc95c 100644
--- a/internal/fetchdatasource/fetchdatasource_test.go
+++ b/internal/fetchdatasource/fetchdatasource_test.go
@@ -338,7 +338,7 @@
}
func TestLocalGetUnitMeta(t *testing.T) {
- ctx, ds, teardown := setup(t, nil, true)
+ ctx, ds, teardown := setup(t, defaultTestModules, true)
defer teardown()
sourceInfo := source.NewGitHubInfo("https://github.com/my/module", "", "v0.0.0")