Skip to content

cmd/cue: cannot add tag injection to required field #4229

@rogpeppe

Description

@rogpeppe

What version of CUE are you using (cue version)?

af0cfc15a

Does this issue reproduce with the latest stable release?

Yes

What did you do?

exec cue export -t field=value x1.cue
cmp stdout want-stdout

exec cue export -t field=value x2.cue
cmp stdout want-stdout

-- x1.cue --
field: string @tag(field)
other: field
-- x2.cue --
field!: string @tag(field)
other: field
-- want-stdout --
{
    "field": "value",
    "other": "value"
}

What did you expect to see?

A passing test. Describing the tagged field as required seems appropriate,
as the configuration does indeed require the field to be filled in by the CUE command's
injection, and a "field is required but not present" error is arguably and earlier
and more obvious failure than an "incomplete value" error.

What did you see instead?

> exec cue export -t field=value x1.cue
[stdout]
{
    "field": "value",
    "other": "value"
}
> cmp stdout want-stdout
> exec cue export -t field=value x2.cue
[stderr]
no tag for "field"
@tag not allowed within field constraint:
    ./x2.cue:1:16
[exit status 1]
FAIL: /tmp/x.txtar:4: unexpected command failure

As an aside, the error message is not very obvious either: I didn't immediately realise that it's referring to a field constraint as distinct from a field itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions