Skip to content

Commit

Permalink
cmd/cue: suggest cue mod fix on all commands to add language.version
Browse files Browse the repository at this point in the history
We did this for commands like `cue mod tidy` or `cue mod publish`,
but not the rest of commands which load CUE packages like `cue export`.
It makes sense to make that suggestion now that language.version
is required in all cases, not just when tidying or publishing.

Fixes #3232.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: I24bdb96de36f1f4586ddd52fe7ad25a4934a2582
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199278
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Matthew Sackman <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
mvdan committed Aug 10, 2024
1 parent 915059d commit 40eed23
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/cue/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func parseArgs(cmd *Command, args []string, cfg *config) (p *buildPlan, err erro

for _, b := range builds {
if b.Err != nil {
return nil, b.Err
return nil, suggestModCommand(b.Err)
}
switch {
case !b.User:
Expand Down
5 changes: 4 additions & 1 deletion cmd/cue/cmd/modtidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ func suggestModCommand(err error) error {
notTidyErr := new(modload.ErrModuleNotTidy)
switch {
case errors.Is(err, modfile.ErrNoLanguageVersion):
err = fmt.Errorf("%w; run 'cue mod fix'", err)
// TODO(mvdan): note that we cannot use standard Go error wrapping here via %w
// as then errors.Print calls errors.Errors which reaches for the first CUE error
// via errors.As, skipping over any non-CUE-wrapped errors.
err = fmt.Errorf("%v; run 'cue mod fix'", err)
case errors.As(err, &notTidyErr):
if notTidyErr.Reason == "" {
err = fmt.Errorf("module is not tidy, use 'cue mod tidy'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cd premodules-downstream-direct
# Downstream consumption via `cue export` fails; when the current module lacks
# a language.version field, we always nudge the user or developer to add one.
! exec cue export
stderr '^no language version declared in module.cue$'
stderr '^no language version declared in module.cue; run ''cue mod fix''$'

# Upstream development works once `cue mod fix` adds a language.version field.
# TODO(mvdan): we don't have anything like `cue mod edit -langversion` if the user wants an older version.
Expand Down

0 comments on commit 40eed23

Please sign in to comment.