this repo has no description
0
fork

Configure Feed

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

cue/load: make MultiplePackageError support relative dir paths

cue/errors already knew how to adjust Error.Msg arguments
of type token.Pos so that their filenames are relative.
However, cue/load.MultiplePackageError reported the directory argument
as simply a string, which we cannot safely know is a filename.

Shove the directory name as a token.Position filename,
which ends up working as the line and column numbers are omitted
when left empty. This is mild abuse of the type, hence the note.
However, being able to point to directory "positions" seems useful.

Then teach cue/errors to make both token.Pos and token.Position
argument filenames relative.

Fixes #3703.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I500b343a4f2b2c681a4649d73c3668d09fc2ecf0
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1214888
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Matthew Sackman <matthew@cue.works>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+22 -14
+2 -2
cmd/cue/cmd/testdata/script/load_pkg.txtar
··· 16 16 17 17 # don't allow mixing two differently named packages 18 18 ! exec cue eval kube.cue foo/kube2.cue 19 - cmpenv stderr different-packages.stderr 19 + cmp stderr different-packages.stderr 20 20 21 21 # When passing multiple CUE files in different directories, 22 22 # cue/load will sort the filenames so that children come later. ··· 35 35 cd .. 36 36 37 37 -- different-packages.stderr -- 38 - found packages "kube" (kube.cue) and "kube2" (kube2.cue) in "${WORK@R}" 38 + found packages "kube" (kube.cue) and "kube2" (kube2.cue) in "." 39 39 -- data.cue -- 40 40 foo:3 41 41 -- t.cue --
+1 -1
cmd/cue/cmd/testdata/script/pkg_resolution_multiple_packages_build_attr.txtar
··· 5 5 cmp stdout eval-all.golden 6 6 7 7 ! exec cue eval -t something ./... 8 - stderr '^found packages "x" \(x.cue\) and "y" \(y.cue\) in ".*x"$' 8 + stderr '^found packages "x" \(x.cue\) and "y" \(y.cue\) in "x"$' 9 9 10 10 # Test that a non-wildcard pattern similarly respects 11 11 # build attributes.
+1 -1
cmd/cue/cmd/testdata/script/pkg_resolution_multiple_packages_no_matching_path_element.txtar
··· 8 8 cmp stderr absolute_stderr.golden 9 9 ! exec cue eval ./x 10 10 # TODO: it would be nice if the error output was similar for this case as the others. 11 - stderr 'found packages "y" \(y.cue\) and "z" \(z.cue\) in ".*"' 11 + stderr 'found packages "y" \(y.cue\) and "z" \(z.cue\) in "x"' 12 12 13 13 -- cue.mod/module.cue -- 14 14 module: "mod.com"
+1 -1
cmd/cue/cmd/testdata/script/pkg_resolution_multiple_packages_one_matching_path_element.txtar
··· 8 8 cmp stdout stdout.golden 9 9 # TODO: the following command fails unexpectedly although it should be consistent with the above. 10 10 ! exec cue eval ./x 11 - stderr 'found packages "x" \(x.cue\) and "y" \(y.cue\) in ".*script-pkg_resolution_multiple_packages_one_matching_path_element.*"' 11 + stderr 'found packages "x" \(x.cue\) and "y" \(y.cue\) in "\./x"' 12 12 13 13 -- stdout.golden -- 14 14 x: 5
+14 -8
cue/errors/errors.go
··· 543 543 // so we make a copy if we need to replace any arguments. 544 544 didCopy := false 545 545 for i, arg := range args { 546 - if arg, ok := arg.(token.Pos); ok { 547 - if !didCopy { 548 - args = slices.Clone(args) 549 - didCopy = true 550 - } 551 - pos := arg.Position() 552 - pos.Filename = relPath(pos.Filename, cfg) 553 - args[i] = pos 546 + var pos token.Position 547 + switch arg := arg.(type) { 548 + case token.Pos: 549 + pos = arg.Position() 550 + case token.Position: 551 + pos = arg 552 + default: 553 + continue 554 554 } 555 + if !didCopy { 556 + args = slices.Clone(args) 557 + didCopy = true 558 + } 559 + pos.Filename = relPath(pos.Filename, cfg) 560 + args[i] = pos 555 561 } 556 562 557 563 n, _ := fmt.Fprintf(w, msg, args...)
+3 -1
cue/load/errors.go
··· 131 131 e.Files[0], 132 132 e.Packages[1], 133 133 e.Files[1], 134 - e.Dir, 134 + // To make sure [cue/errors] prints this directory name as relative, 135 + // use a [token.Position] even though it's really only meant for regular source files. 136 + token.Position{Filename: e.Dir}, 135 137 } 136 138 } 137 139