Skip to content

Commit

Permalink
internal/mod/modpkgload: propagate CUE syntax error
Browse files Browse the repository at this point in the history
When there's a syntax error reading CUE syntax, the
error details were being hidden. This resulted
in issue #3281. Using `%w` instead of `%v` fixes this.

Fixes #3281.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I43e49cde84319de9a20a395eea46664831e8a470
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1197984
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
  • Loading branch information
rogpeppe committed Jul 19, 2024
1 parent af808c3 commit a36cc32
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions cmd/cue/cmd/testdata/script/issue3281.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# When there's a syntax error encountered at an early
# stage of processing, the error message should
# point to the place in the file where the error was
# encountered.

! exec cue eval invalid.cue
stderr invalid.cue:3:
-- cue.mod/module.cue --
module: "test.example"
language: version: "v0.9.0"

-- invalid.cue --
package blah

self: bad )
syntax
2 changes: 1 addition & 1 deletion cue/load/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func loadPackages(
}
syntax, err := cfg.fileSystem.getCUESyntax(f)
if err != nil {
return nil, fmt.Errorf("cannot get syntax for %q: %v", f.Filename, err)
return nil, fmt.Errorf("cannot get syntax for %q: %w", f.Filename, err)
}
for _, imp := range syntax.Imports {
pkgPath, err := strconv.Unquote(imp.Path.Value)
Expand Down

0 comments on commit a36cc32

Please sign in to comment.