Skip to content

Commit 0eeccf0

Browse files
committed
internal/fetchdatasource: GetUnitMeta returns NotFound on missing package
If a module exists but the package path is not in it, return NotFound. For golang/go#47780 Change-Id: If3a6602df4b99c8470020e8538e01c685880d86d Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/345251 Trust: Jonathan Amsterdam <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]> Reviewed-by: Julie Qiu <[email protected]>
1 parent ac26f27 commit 0eeccf0

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

internal/fetchdatasource/fetchdatasource.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,12 @@ func (ds *FetchDataSource) GetUnitMeta(ctx context.Context, path, requestedModul
181181
Path: path,
182182
ModuleInfo: module.ModuleInfo,
183183
}
184-
if u := findUnit(module, path); u != nil {
185-
um.Name = u.Name
186-
um.IsRedistributable = u.IsRedistributable
184+
u := findUnit(module, path)
185+
if u == nil {
186+
return nil, derrors.NotFound
187187
}
188+
um.Name = u.Name
189+
um.IsRedistributable = u.IsRedistributable
188190
return um, nil
189191
}
190192

internal/fetchdatasource/fetchdatasource_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,9 @@ func TestGetLatestInfo(t *testing.T) {
309309
wantErr: derrors.NotFound,
310310
},
311311
{
312-
fullPath: "foo.com/bar/baz",
313-
modulePath: "foo.com/bar",
314-
wantModulePath: "foo.com/bar/v3",
315-
wantPackagePath: "foo.com/bar/v3",
312+
fullPath: "foo.com/bar/baz",
313+
modulePath: "foo.com/bar",
314+
wantErr: derrors.NotFound,
316315
},
317316
{
318317
fullPath: "incompatible.com/bar",
@@ -424,6 +423,12 @@ func TestLocalGetUnitMeta(t *testing.T) {
424423
modulePath: stdlib.ModulePath,
425424
wantErr: derrors.InvalidArgument,
426425
},
426+
{
427+
// Module is known but path isn't in it.
428+
path: "github.com/my/module/unk",
429+
modulePath: "github.com/my/module",
430+
wantErr: derrors.NotFound,
431+
},
427432
} {
428433
t.Run(test.path, func(t *testing.T) {
429434
got, err := ds.GetUnitMeta(ctx, test.path, test.modulePath, fetch.LocalVersion)

0 commit comments

Comments
 (0)