this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/mod/modload: rewrite "missing dependency" errors in CheckTidy

That is, telling the user

module is not tidy, use 'cue mod tidy': cannot find module providing package example.com@v0:main

may be confusing, as example.com likely does exist in a registry
and will be added once they run 'cue mod tidy'.
"cannot find module" is a bit of a lie as CheckTidy does not try to
fetch missing dependencies from registries.

Instead, we now say:

module is not tidy, use 'cue mod tidy': missing dependency providing package example.com@v0:main

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ia1549bdc2a1c97c17e29e7e8914085c5c680724e
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195701
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Paul Jolly <paul@myitcv.io>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+23 -14
+1 -1
cmd/cue/cmd/testdata/script/modtidy_check_fail.txtar
··· 4 4 cmp stderr want-stderr 5 5 6 6 -- want-stderr -- 7 - module is not tidy, use 'cue mod tidy': cannot find module providing package example.com@v0:main 7 + module is not tidy, use 'cue mod tidy': missing dependency providing package example.com@v0:main 8 8 -- cue.mod/module.cue -- 9 9 module: "main.org@v0" 10 10 language: version: "v0.8.0"
+1 -1
internal/mod/modload/testdata/tidy/badimportpath.txtar
··· 1 1 # Test that using a bad import path does not result in a panic. 2 2 3 3 -- tidy-check-error -- 4 - module is not tidy: cannot find module providing package x.com/Foo--bar@v0 4 + module is not tidy: missing dependency providing package x.com/Foo--bar@v0 5 5 -- want -- 6 6 error: failed to resolve "x.com/Foo--bar@v0": cannot obtain versions for module "x.com/Foo--bar@v0": module x.com/Foo--bar@v0: invalid OCI request: name invalid: invalid repository name 7 7 -- cue.mod/module.cue --
+1 -1
internal/mod/modload/testdata/tidy/canuseprerelease.txtar
··· 2 2 # no stable releases available. 3 3 4 4 -- tidy-check-error -- 5 - module is not tidy: cannot find module providing package example.com@v0:main 5 + module is not tidy: missing dependency providing package example.com@v0:main 6 6 -- want -- 7 7 module: "main.org@v0" 8 8 language: {
+1 -1
internal/mod/modload/testdata/tidy/cuemod-local.txtar
··· 3 3 # all works and passes the tidy check. 4 4 5 5 -- tidy-check-error -- 6 - module is not tidy: cannot find module providing package example.com@v0:main 6 + module is not tidy: missing dependency providing package example.com@v0:main 7 7 -- want -- 8 8 module: "main.org@v0" 9 9 language: {
+1 -1
internal/mod/modload/testdata/tidy/implied-major-version-ambiguity.txtar
··· 7 7 -- want -- 8 8 error: failed to resolve "example.com/foo": cannot find module providing package example.com/foo 9 9 -- tidy-check-error -- 10 - module is not tidy: cannot find module providing package example.com/bar@v1 10 + module is not tidy: missing dependency providing package example.com/bar@v1 11 11 -- cue.mod/module.cue -- 12 12 module: "main.org@v0" 13 13 language: version: "v0.8.0"
+2 -2
internal/mod/modload/testdata/tidy/implied-major-version-without-explicit-default.txtar
··· 1 - # This test checks we can have have an import with an implied major version 1 + # This test checks we can have an import with an implied major version 2 2 # when there's no explicit default in the module file. 3 3 -- tidy-check-error -- 4 - module is not tidy: cannot find module providing package .* 4 + module is not tidy: missing dependency providing package .* 5 5 -- want -- 6 6 module: "main.org@v0" 7 7 language: {
+1 -1
internal/mod/modload/testdata/tidy/nested-deps.txtar
··· 2 2 # and a module that's unused. 3 3 4 4 -- tidy-check-error -- 5 - module is not tidy: cannot find module providing package example.com.* 5 + module is not tidy: missing dependency providing package example.com.* 6 6 -- want -- 7 7 module: "main.org@v0" 8 8 language: {
+1 -1
internal/mod/modload/testdata/tidy/packagenotfound.txtar
··· 1 1 # Test what happens when we try to import a package that does not exist. 2 2 3 3 -- tidy-check-error -- 4 - module is not tidy: cannot find module providing package example.com/nonexistent@v0 4 + module is not tidy: missing dependency providing package example.com/nonexistent@v0 5 5 -- want -- 6 6 error: failed to resolve "example.com/nonexistent@v0": cannot find module providing package example.com/nonexistent@v0 7 7 -- cue.mod/module.cue --
+1 -1
internal/mod/modload/testdata/tidy/preferstable.txtar
··· 2 2 # pre-releases. 3 3 4 4 -- tidy-check-error -- 5 - module is not tidy: cannot find module providing package example.com.* 5 + module is not tidy: missing dependency providing package example.com.* 6 6 -- want -- 7 7 module: "main.org@v0" 8 8 language: {
+13 -4
internal/mod/modload/tidy.go
··· 184 184 pkgs := modpkgload.LoadPackages(ctx, ld.mainModule.Path(), ld.mainModuleLoc, rs, ld.registry, rootPkgPaths) 185 185 if ld.checkTidy { 186 186 for _, pkg := range pkgs.All() { 187 - if err := pkg.Error(); err != nil { 188 - // TODO: transform "cannot find module" error as it may be confusing 189 - // when the module does exist in the registry. 190 - return nil, nil, &ErrModuleNotTidy{Reason: err.Error()} 187 + err := pkg.Error() 188 + if err == nil { 189 + continue 190 + } 191 + missingErr := new(modpkgload.ImportMissingError) 192 + // "cannot find module providing package P" is confusing here, 193 + // as checkTidy simply points out missing dependencies without fetching them. 194 + if errors.As(err, &missingErr) { 195 + err = &ErrModuleNotTidy{Reason: fmt.Sprintf( 196 + "missing dependency providing package %s", missingErr.Path)} 197 + } else { 198 + panic(fmt.Sprintf("%#v\n", err) + ": " + err.Error()) 191 199 } 200 + return nil, nil, err 192 201 } 193 202 // All packages could be loaded OK so there are no new 194 203 // dependencies to be resolved and nothing to do.