Skip to content

Commit 9a88d06

Browse files
committed
cmd/cue: improve error message for malformed module path
When a module file's module directive holds an invalid module path, the error message did not include the file name where the error was. Example of previous error message: invalid module path "": path "" has no major version New error message: cue.mod/module.cue: invalid module path: path "" has no major version This fix applies to all the subcommands that use `readModuleFile`: `cue mod edit`, `cue mod get`, and `cue mod resolve`. Fixes #3259 Signed-off-by: Roger Peppe <[email protected]> Change-Id: I175a234ddc26ce42a76602b23fbfabf59ec640ad Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1197923 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent f2066e3 commit 9a88d06

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Check that the error message when there's a bad module
2+
# path includes the path to the offending file (issue 3259)
3+
4+
! exec cue mod get example.com/foo
5+
cmp stderr want-stderr
6+
-- want-stderr --
7+
cue.mod/module.cue: invalid module path: path "" has no major version
8+
-- cue.mod/module.cue --
9+
module: ""
10+
language: version: "v0.9.2"
11+

internal/mod/modload/tidy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func readModuleFile(fsys fs.FS, modRoot string) (module.Version, *modfile.File,
141141
}
142142
mainModuleVersion, err := module.NewVersion(mf.QualifiedModule(), "")
143143
if err != nil {
144-
return module.Version{}, nil, fmt.Errorf("invalid module path %q: %v", mf.QualifiedModule(), err)
144+
return module.Version{}, nil, fmt.Errorf("%s: invalid module path: %v", modFilePath, err)
145145
}
146146
return mainModuleVersion, mf, nil
147147
}

0 commit comments

Comments
 (0)