cue icon indicating copy to clipboard operation
cue copied to clipboard

cmd/cue: file embedding not working inputs are CUE files

Open jpluscplusm opened this issue 10 months ago • 3 comments

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

$ cue version
cue version v0.12.0

go version go1.23.5
      -buildmode exe
       -compiler gc
  DefaultGODEBUG asynctimerchan=1,gotypesalias=0,httpservecontentkeepheaders=1,tls3des=1,tlskyber=0,x509keypairleaf=0,x509negativeserial=1
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
cue.lang.version v0.12.0

Does this issue reproduce with the latest stable release?

v0.12.0 is latest.

What did you do?

# Evaluate a CUE package that uses file embedding
exec cue export .:p
cmp stdout stdout.golden

# Evaluate a CUE file that uses file embedding.
exec cue export file.cue
cmp stdout stdout.golden
-- cue.mod/module.cue --
module: "mod.example"
language: version: "v0.10.0"
-- file.cue --
@extern(embed)

package p

files: _ @embed(file=some.txt)
-- some.txt --
hello
-- stdout.golden --
{
    "files": "hello\n"
}

What did you expect to see?

A passing test.

What did you see instead?

# Evaluate a CUE package that uses file embedding (0.012s)
# Evaluate a CUE file that uses file embedding. (0.011s)
> exec cue export file.cue
[stderr]
cannot embed files when not in a module
[exit status 1]
FAIL: /tmp/testscript2371849007/repro.txtar/script.txtar:6: unexpected command failure
error running repro.txtar in /tmp/testscript2371849007/repro.txtar

Assuming that embedding files is permitted when the containing CUE file is referred to directly, instead of via an import path. I scanned through the file embedding proposal and didn't notice anything obvious that would disqualify the failing cue invocation.

Alternatively, if the direct file invocation method is forbidden, I would expect a better error message that didn't refer to being "not in a module", despite definitely having invoked cue whilst "inside a module".

jpluscplusm avatar Feb 06 '25 14:02 jpluscplusm

The expectation that this should work with regular CUE files is correct to my mind. I've updated the repro and description slightly to reflect that.

myitcv avatar Feb 08 '25 06:02 myitcv

agreed to the point I raised a dupe! https://github.com/cue-lang/cue/issues/4141

mvdan avatar Oct 17 '25 14:10 mvdan

I'm going to slightly prioritize this, because embedding is a rather useful feature, so users keep running into this - including myself.

mvdan avatar Oct 21 '25 13:10 mvdan