-
Notifications
You must be signed in to change notification settings - Fork 347
Open
Labels
NeedsFixdefaultsvetcandidate for a vet rule to detect suspect usagecandidate for a vet rule to detect suspect usage
Description
What version of CUE are you using (cue version)?
$ cue version cue version 0.4.0 linux/amd64
(Git tag v0.4.0)
Does this issue reproduce with the latest release?
Yes. Tested on master as well (38c8f7d).
What did you do?
It is known that a field cannot have multiple different default values.
However, a user of a field with a default may not always know that it has one. The error when they try to assign a default is not very helpful.
tmpdir="$(mktemp -d)"
cd "$tmpdir"
trap 'rm -r "$tmpdir"' EXIT
alias cat=$(which bat >/dev/null && echo bat || echo cat)
cat > issue.cue <<EOF
#Foo: {
target: int | *100
}
#Bar: #Foo & {
target: int | *200
}
baz: #Bar & {
// no value for target
}
EOF
cat issue.cue
echo
echo "Undescriptive error message:"
echo
echo \$ cue export issue.cue
cue export issue.cue
echo
echo "We don't know which field causes the failure unless we manually check:"
echo
echo \$ cue eval issue.cue
cue eval issue.cue
echo
echo "Workaround if you want to 'override' the default:"
echo
cat > issue-ok.cue <<EOF
#Foo: {
target: uint | *100
}
#Bar: #Foo & {
_target: uint | *null
if _target == null {
target: 200
}
if _target != null {
target: _target
}
}
baz: #Bar & {
// toggle this
// _target: 300
}
EOF
cat issue-ok.cueWhat did you expect to see?
Something more descriptive that tells me that the target field fails to evaluate.
It would be best if the conflicting default values could be listed just like with other concrete values:
#Bar.target: conflicting values 200 and 100:
./issue.cue:2:10
./issue.cue:5:7
./issue.cue:6:10
baz.target: conflicting values 200 and 100:
./issue.cue:2:10
./issue.cue:5:7
./issue.cue:6:10
./issue.cue:9:6
What did you see instead?
Only the containing struct is listed:
baz:
This becomes much harder to track down in bigger structs.
Metadata
Metadata
Assignees
Labels
NeedsFixdefaultsvetcandidate for a vet rule to detect suspect usagecandidate for a vet rule to detect suspect usage