Skip to content

Commit

Permalink
internal/core/adt: shorter validator error message
Browse files Browse the repository at this point in the history
Validator errors can get very long, dwarfing the rest of the errors, as
the validator error currently prints the entire source expression that's
being validated. It's made worse by the fact that references have been
expanded at this point.

This is not the approach taken by most validation failures: instead we
can rely on the fact that the source expression is available at the the
source locations referred to by the error.

So we change the error to include only the name of the validator when
the validator can take non-concrete arguments, because those seem to be
the biggest culprits here.

Also, having a string-returning method is a little more convenient for
obtaining the qualified name of a builtin, and there's no need for it to
be exported, so rename it to `qualifiedName`.

Also, there's no need to build the buffer with the arguments when
we're not going to use it, so move the `Unwrap` test before that,
which should not alter semantics.

Fixes #3550.

Signed-off-by: Roger Peppe <[email protected]>
Change-Id: Ic4586fd3a335263ff9309b8c5b47f06a30fefc17
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1203562
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Unity-Result: CUE porcuepine <[email protected]>
  • Loading branch information
rogpeppe committed Nov 6, 2024
1 parent 93c1d7e commit af459f1
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 296 deletions.
2 changes: 1 addition & 1 deletion cmd/cue/cmd/testdata/script/vet_yaml.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
cmp stderr expect-stderr

-- expect-stderr --
phrases: invalid value "phrases:\n # A quote from Mark Twain.\n quote1:\n lang: en\n attribution: Mark Twain\n\n # A Norwegian proverb.\n proverb:\n lang: no\n text: Stemmen som sier at du ikke klarer det, lyver." (does not satisfy encoding/yaml.Validate({phrases:{},#Phrase:{lang:=~"^[a-zA-Z0-9-_]{2,}$" | false,text:!="",attribution?:!=""},#LanguageTag:=~"^[a-zA-Z0-9-_]{2,}$" | false})): error in call to encoding/yaml.Validate: incomplete value !="":
phrases: invalid value "phrases:\n # A quote from Mark Twain.\n quote1:\n lang: en\n attribution: Mark Twain\n\n # A Norwegian proverb.\n proverb:\n lang: no\n text: Stemmen som sier at du ikke klarer det, lyver." (does not satisfy encoding/yaml.Validate): error in call to encoding/yaml.Validate: incomplete value !="":
./yaml.cue:19:10
./yaml.cue:11:17
./yaml.cue:21:10
Expand Down
16 changes: 8 additions & 8 deletions cue/testdata/builtins/matchif.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ Conjuncts: 154
Disjuncts: 98
-- out/eval --
Errors:
regularFields.err1: invalid value {x:10,y:6} (does not satisfy matchIf({x!:>2}, {y!:5}, {y!:1})): conflicting values 5 and 6:
regularFields.err1: invalid value {x:10,y:6} (does not satisfy matchIf): conflicting values 5 and 6:
./in.cue:2:7
./in.cue:2:30
./in.cue:7:8
./in.cue:7:19
regularFields.err2: invalid value {x:11,y:6} (does not satisfy matchIf({x!:>2}, {y!:5}, {y!:1})): conflicting values 5 and 6:
regularFields.err2: invalid value {x:11,y:6} (does not satisfy matchIf): conflicting values 5 and 6:
./in.cue:2:7
./in.cue:2:30
./in.cue:8:8
./in.cue:8:19
regularFields.err3: invalid value {x:2,y:5} (does not satisfy matchIf({x!:>2}, {y!:5}, {y!:1})): conflicting values 1 and 5:
regularFields.err3: invalid value {x:2,y:5} (does not satisfy matchIf): conflicting values 1 and 5:
./in.cue:2:7
./in.cue:2:39
./in.cue:9:8
./in.cue:9:18
regularFields.err4: invalid value {x:1,y:2} (does not satisfy matchIf({x!:>2}, {y!:5}, {y!:1})): conflicting values 1 and 2:
regularFields.err4: invalid value {x:1,y:2} (does not satisfy matchIf): conflicting values 1 and 2:
./in.cue:2:7
./in.cue:2:39
./in.cue:10:8
Expand Down Expand Up @@ -65,7 +65,7 @@ Result:
y: (int){ 1 }
}
err1: (_|_){
// [eval] regularFields.err1: invalid value {x:10,y:6} (does not satisfy matchIf({x!:>2}, {y!:5}, {y!:1})): conflicting values 5 and 6:
// [eval] regularFields.err1: invalid value {x:10,y:6} (does not satisfy matchIf): conflicting values 5 and 6:
// ./in.cue:2:7
// ./in.cue:2:30
// ./in.cue:7:8
Expand All @@ -74,7 +74,7 @@ Result:
y: (int){ 6 }
}
err2: (_|_){
// [eval] regularFields.err2: invalid value {x:11,y:6} (does not satisfy matchIf({x!:>2}, {y!:5}, {y!:1})): conflicting values 5 and 6:
// [eval] regularFields.err2: invalid value {x:11,y:6} (does not satisfy matchIf): conflicting values 5 and 6:
// ./in.cue:2:7
// ./in.cue:2:30
// ./in.cue:8:8
Expand All @@ -83,7 +83,7 @@ Result:
y: (int){ 6 }
}
err3: (_|_){
// [eval] regularFields.err3: invalid value {x:2,y:5} (does not satisfy matchIf({x!:>2}, {y!:5}, {y!:1})): conflicting values 1 and 5:
// [eval] regularFields.err3: invalid value {x:2,y:5} (does not satisfy matchIf): conflicting values 1 and 5:
// ./in.cue:2:7
// ./in.cue:2:39
// ./in.cue:9:8
Expand All @@ -92,7 +92,7 @@ Result:
y: (int){ 5 }
}
err4: (_|_){
// [eval] regularFields.err4: invalid value {x:1,y:2} (does not satisfy matchIf({x!:>2}, {y!:5}, {y!:1})): conflicting values 1 and 2:
// [eval] regularFields.err4: invalid value {x:1,y:2} (does not satisfy matchIf): conflicting values 1 and 2:
// ./in.cue:2:7
// ./in.cue:2:39
// ./in.cue:10:8
Expand Down
204 changes: 78 additions & 126 deletions cue/testdata/builtins/matchn.txtar

Large diffs are not rendered by default.

116 changes: 24 additions & 92 deletions cue/testdata/builtins/validators.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,26 @@ Disjuncts: 131
Errors:
callOfCallToValidator.e: cannot call previously called validator b:
./in.cue:94:5
issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t1: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
./issue3418.cue:1:24
./issue3418.cue:1:16
./issue3418.cue:1:31
./issue3418.cue:1:35
./issue3418.cue:1:37
issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t2: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
./issue3418.cue:2:41
./issue3418.cue:2:16
./issue3418.cue:2:48
./issue3418.cue:2:52
./issue3418.cue:2:54
issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t3.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
./issue3418.cue:6:5
./issue3418.cue:4:5
./issue3418.cue:5:5
./issue3418.cue:6:12
./issue3418.cue:6:16
./issue3418.cue:6:18
issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t4.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
./issue3418.cue:10:5
./issue3418.cue:9:5
./issue3418.cue:10:12
Expand All @@ -235,12 +235,12 @@ issue3474.structValidator.failClosed.#A: invalid value {} (does not satisfy stru
./issue3474.cue:27:6
./issue3474.cue:27:23
./issue3474.cue:28:6
issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN(1, [>10])): 0 matched, expected 1:
issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
./issue3474.cue:41:5
./issue3474.cue:41:12
./issue3474.cue:42:5
./issue3474.cue:43:12
issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN(1, [>10])): 0 matched, expected 1:
issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN): 0 matched, expected 1:
./issue3474.cue:53:5
./issue3474.cue:53:12
./issue3474.cue:54:5
Expand Down Expand Up @@ -346,15 +346,15 @@ Result:
issue3418: (_|_){
// [eval]
t1: (_|_){
// [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
// ./issue3418.cue:1:24
// ./issue3418.cue:1:16
// ./issue3418.cue:1:31
// ./issue3418.cue:1:35
// ./issue3418.cue:1:37
}
t2: (_|_){
// [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
// ./issue3418.cue:2:41
// ./issue3418.cue:2:16
// ./issue3418.cue:2:48
Expand All @@ -364,7 +364,7 @@ Result:
t3: (_|_){
// [eval]
x: (_|_){
// [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
// ./issue3418.cue:6:5
// ./issue3418.cue:4:5
// ./issue3418.cue:5:5
Expand All @@ -376,7 +376,7 @@ Result:
t4: (_|_){
// [eval]
x: (_|_){
// [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
// ./issue3418.cue:10:5
// ./issue3418.cue:9:5
// ./issue3418.cue:10:12
Expand Down Expand Up @@ -432,7 +432,7 @@ Result:
fail: (_|_){
// [eval]
A: (_|_){
// [eval] issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN(1, [>10])): 0 matched, expected 1:
// [eval] issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
// ./issue3474.cue:41:5
// ./issue3474.cue:41:12
// ./issue3474.cue:42:5
Expand All @@ -448,7 +448,7 @@ Result:
failType: (_|_){
// [eval]
A: (_|_){
// [eval] issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN(1, [>10])): 0 matched, expected 1:
// [eval] issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN): 0 matched, expected 1:
// ./issue3474.cue:53:5
// ./issue3474.cue:53:12
// ./issue3474.cue:54:5
Expand All @@ -462,38 +462,6 @@ Result:
diff old new
--- old
+++ new
@@ -1,19 +1,19 @@
Errors:
callOfCallToValidator.e: cannot call previously called validator b:
./in.cue:94:5
-issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:1:24
./issue3418.cue:1:16
./issue3418.cue:1:31
./issue3418.cue:1:35
./issue3418.cue:1:37
-issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:2:41
./issue3418.cue:2:16
./issue3418.cue:2:48
./issue3418.cue:2:52
./issue3418.cue:2:54
-issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:6:5
./issue3418.cue:4:5
./issue3418.cue:5:5
@@ -20,7 +20,7 @@
./issue3418.cue:6:12
./issue3418.cue:6:16
./issue3418.cue:6:18
-issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
./issue3418.cue:10:5
./issue3418.cue:9:5
./issue3418.cue:10:12
@@ -27,7 +27,7 @@
./issue3418.cue:10:16
./issue3418.cue:10:18
Expand All @@ -516,42 +484,6 @@ diff old new
_a: (_|_){
// [incomplete] issue2098.incomplete1._a: invalid value [] (does not satisfy list.MinItems(1)): len(list) < MinItems(1) (0 < 1):
// ./in.cue:112:6
@@ -150,7 +146,7 @@
issue3418: (_|_){
// [eval]
t1: (_|_){
- // [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+ // [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:1:24
// ./issue3418.cue:1:16
// ./issue3418.cue:1:31
@@ -158,7 +154,7 @@
// ./issue3418.cue:1:37
}
t2: (_|_){
- // [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+ // [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:2:41
// ./issue3418.cue:2:16
// ./issue3418.cue:2:48
@@ -168,7 +164,7 @@
t3: (_|_){
// [eval]
x: (_|_){
- // [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+ // [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:6:5
// ./issue3418.cue:4:5
// ./issue3418.cue:5:5
@@ -180,7 +176,7 @@
t4: (_|_){
// [eval]
x: (_|_){
- // [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
+ // [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(0: conflicting values 2 and 1))): conflicting values 2 and 1:
// ./issue3418.cue:10:5
// ./issue3418.cue:9:5
// ./issue3418.cue:10:12
@@ -202,7 +198,7 @@
failAfter: (_|_){
// [eval]
Expand All @@ -574,26 +506,26 @@ diff old new
Errors:
callOfCallToValidator.e: cannot call previously called validator b:
./in.cue:94:5
issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t1: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
./issue3418.cue:1:24
./issue3418.cue:1:16
./issue3418.cue:1:31
./issue3418.cue:1:35
./issue3418.cue:1:37
issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t2: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
./issue3418.cue:2:41
./issue3418.cue:2:16
./issue3418.cue:2:48
./issue3418.cue:2:52
./issue3418.cue:2:54
issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t3.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
./issue3418.cue:6:5
./issue3418.cue:4:5
./issue3418.cue:5:5
./issue3418.cue:6:12
./issue3418.cue:6:16
./issue3418.cue:6:18
issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
issue3418.t4.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
./issue3418.cue:10:5
./issue3418.cue:9:5
./issue3418.cue:10:12
Expand All @@ -608,12 +540,12 @@ issue3474.structValidator.failClosed.#A: invalid value {} (does not satisfy stru
./issue3474.cue:27:6
./issue3474.cue:27:23
./issue3474.cue:28:6
issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN(1, [>10])): 0 matched, expected 1:
issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
./issue3474.cue:41:5
./issue3474.cue:41:12
./issue3474.cue:42:5
./issue3474.cue:43:12
issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN(1, [>10])): 0 matched, expected 1:
issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN): 0 matched, expected 1:
./issue3474.cue:53:5
./issue3474.cue:53:12
./issue3474.cue:54:5
Expand Down Expand Up @@ -723,15 +655,15 @@ Result:
issue3418: (_|_){
// [eval]
t1: (_|_){
// [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t1: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
// ./issue3418.cue:1:24
// ./issue3418.cue:1:16
// ./issue3418.cue:1:31
// ./issue3418.cue:1:35
// ./issue3418.cue:1:37
}
t2: (_|_){
// [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t2: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
// ./issue3418.cue:2:41
// ./issue3418.cue:2:16
// ./issue3418.cue:2:48
Expand All @@ -741,7 +673,7 @@ Result:
t3: (_|_){
// [eval]
x: (_|_){
// [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t3.0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t3.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
// ./issue3418.cue:6:5
// ./issue3418.cue:4:5
// ./issue3418.cue:5:5
Expand All @@ -753,7 +685,7 @@ Result:
t4: (_|_){
// [eval]
x: (_|_){
// [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN(1, _|_(issue3418.t4.0: conflicting values 2 and 1))): conflicting values 2 and 1:
// [eval] issue3418.t4.x: invalid value "foo" (does not satisfy matchN): conflicting values 2 and 1:
// ./issue3418.cue:10:5
// ./issue3418.cue:9:5
// ./issue3418.cue:10:12
Expand Down Expand Up @@ -809,7 +741,7 @@ Result:
fail: (_|_){
// [eval]
A: (_|_){
// [eval] issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN(1, [>10])): 0 matched, expected 1:
// [eval] issue3474.topValidator.fail.A: invalid value 1 (does not satisfy matchN): 0 matched, expected 1:
// ./issue3474.cue:41:5
// ./issue3474.cue:41:12
// ./issue3474.cue:42:5
Expand All @@ -825,7 +757,7 @@ Result:
failType: (_|_){
// [eval]
A: (_|_){
// [eval] issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN(1, [>10])): 0 matched, expected 1:
// [eval] issue3474.topValidator.failType.A: invalid value {C:1} (does not satisfy matchN): 0 matched, expected 1:
// ./issue3474.cue:53:5
// ./issue3474.cue:53:12
// ./issue3474.cue:54:5
Expand Down
Loading

0 comments on commit af459f1

Please sign in to comment.