Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cue: tool/exec.Run doesn't handle lists of environment variables #2763

Closed
nickfiggins opened this issue Jan 9, 2024 · 1 comment
Closed
Labels

Comments

@nickfiggins
Copy link
Contributor

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

$ cue version
cue version v0.7.0

go version go1.21.5
      -buildmode exe
       -compiler gc
       -trimpath true
     CGO_ENABLED 0
          GOARCH amd64
            GOOS darwin
         GOAMD64 v1

Does this issue reproduce with the latest stable release?

yes

What did you do?

exec cue cmd envFromList
stdout FOO=BAR
-- a_tool.cue --
package p

import "tool/exec"

command: envFromList: exec.Run & {
	cmd: "env"
	env: ["FOO=BAR"]
}

What did you expect to see?

A passing test (as a result of FOO=BAR populated in the command output).

What did you see instead?

> exec cue cmd envFromList
            [stderr]
            command.envFromList.env: conflicting values ["FOO=BAR"] and {[string]:(string|[...=~"="])} (mismatched types list and struct):
                ./a_tool.cue:5:23
                ./a_tool.cue:7:7
                tool/exec:6:8
            [exit status 1]
            FAIL: testdata/script/cmd_execenv.txtar:1: unexpected command failure

Per the docs (and implementation), it seems like this usage of env is meant to be supported. It seems like this just may be due to the order of operations in the env definition which leads to this schema being generated

@mvdan
Copy link
Member

mvdan commented Jan 9, 2024

Thanks - this looks like a mistake in the schema. I think env: [string]: string | [...=~"="] should be env: {[string]: string} | [...=~"="] so that the disjunction applies to the entire [string]: string, otherwise it applies to just string on the left side. See: https://tip.cuelang.org/play/?id=Q2sENh20fvy#cue@export@cue

@mvdan mvdan added NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Jan 9, 2024
cueckoo pushed a commit that referenced this issue Jan 13, 2024
Currently, supplying env vars as a list in exec.Run
results in an error due to a bug in the schema
definition.

This updates the spec to allow for lists of environment
variables as expected.

Fixes #2763.

Signed-off-by: Nick Figgins <[email protected]>
Change-Id: Iea3b1a2087e48a1493ca4709df542a271d3584b0
Signed-off-by: Nick Figgins <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants