cue
cue copied to clipboard
cmd/cue: panic when JSON/YAML input is empty
What version of CUE are you using (cue version)?
$ cue version
cue version v0.6.0
go version go1.20.6
-buildmode exe
-compiler gc
-trimpath true
CGO_ENABLED 0
GOARCH amd64
GOOS linux
GOAMD64 v1
Does this issue reproduce with the latest stable release?
Yes, 0.6.0
What did you do?
! exec cue export json: /dev/null
! stderr panic
I was using a shell pipeline, feeding yaml into cue export file.cue yaml: -. I didn't catch the fact that the pipeline ahead of the cue invocation had failed, resulting in cue's stdin being closed, totally empty.
The above txtar emulates that failure mode without having to use a shell pipeline.
What did you expect to see?
I expected to see some other (error?) message, and not a panic.
What did you see instead?
> ! exec cue export json: /dev/null
[stderr]
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xbe1f6c]
goroutine 1 [running]:
panic({0xcb4de0, 0x13d73a0})
runtime/panic.go:987 +0x3bb fp=0xc0003db888 sp=0xc0003db7c8 pc=0x43583b
cuelang.org/go/cmd/cue/cmd.recoverError(0xc0003dbeb8)
cuelang.org/[email protected]/cmd/cue/cmd/root.go:318 +0x7b fp=0xc0003db8a8 sp=0xc0003db888 pc=0xbfd19b
cuelang.org/go/cmd/cue/cmd.(*Command).Run.func1()
cuelang.org/[email protected]/cmd/cue/cmd/root.go:301 +0x26 fp=0xc0003db8c0 sp=0xc0003db8a8 pc=0xbfd0e6
runtime.deferCallSave(0xc0003db990, 0xc0003dbec8?)
runtime/panic.go:796 +0x88 fp=0xc0003db8d0 sp=0xc0003db8c0 pc=0x435428
runtime.runOpenDeferFrame(0xc0003a5310)
runtime/panic.go:769 +0x1b4 fp=0xc0003db918 sp=0xc0003db8d0 pc=0x435254
panic({0xcb4de0, 0x13d73a0})
runtime/panic.go:884 +0x213 fp=0xc0003db9d8 sp=0xc0003db918 pc=0x435693
runtime.panicmem(...)
runtime/panic.go:260
runtime.sigpanic()
runtime/signal_unix.go:841 +0x37d fp=0xc0003dba38 sp=0xc0003db9d8 pc=0x44c15d
cuelang.org/go/cmd/cue/cmd.(*instance).Value(...)
cuelang.org/[email protected]/cmd/cue/cmd/common.go:206
cuelang.org/go/cmd/cue/cmd.(*instanceIterator).value(0xc0004141a0?)
cuelang.org/[email protected]/cmd/cue/cmd/common.go:223 +0x2c fp=0xc0003dba78 sp=0xc0003dba38 pc=0xbe1f6c
cuelang.org/go/cmd/cue/cmd.runExport(0xc0003b31d0?, {0xc00038b6e0, 0x2, 0x2})
cuelang.org/[email protected]/cmd/cue/cmd/export.go:116 +0x1ef fp=0xc0003dbb90 sp=0xc0003dba78 pc=0xbea54f
cuelang.org/go/cmd/cue/cmd.mkRunE.func1(0xc000402000?, {0xc00038b6e0, 0x2, 0x2})
cuelang.org/[email protected]/cmd/cue/cmd/root.go:87 +0xb3 fp=0xc0003dbcb8 sp=0xc0003dbb90 pc=0xbfc3f3
github.com/spf13/cobra.(*Command).execute(0xc000402000, {0xc00038b680, 0x2, 0x2})
github.com/spf13/[email protected]/command.go:940 +0x862 fp=0xc0003dbdf0 sp=0xc0003dbcb8 pc=0x5e0a22
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002c8f00)
github.com/spf13/[email protected]/command.go:1068 +0x3bd fp=0xc0003dbea8 sp=0xc0003dbdf0 pc=0x5e129d
github.com/spf13/cobra.(*Command).Execute(...)
github.com/spf13/[email protected]/command.go:992
cuelang.org/go/cmd/cue/cmd.(*Command).Run(0xc0003b31d0, {0x3?, 0x3?})
cuelang.org/[email protected]/cmd/cue/cmd/root.go:303 +0x6b fp=0xc0003dbef0 sp=0xc0003dbea8 pc=0xbfcfcb
cuelang.org/go/cmd/cue/cmd.Main()
cuelang.org/[email protected]/cmd/cue/cmd/root.go:231 +0x79 fp=0xc0003dbf68 sp=0xc0003dbef0 pc=0xbfccb9
main.main()
cuelang.org/[email protected]/cmd/cue/main.go:24 +0x19 fp=0xc0003dbf80 sp=0xc0003dbf68 pc=0xc151f9
runtime.main()
runtime/proc.go:250 +0x207 fp=0xc0003dbfe0 sp=0xc0003dbf80 pc=0x4385a7
runtime.goexit()
runtime/asm_amd64.s:1598 +0x1 fp=0xc0003dbfe8 sp=0xc0003dbfe0 pc=0x467c61
goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
runtime/proc.go:381 +0xd6 fp=0xc000056fb0 sp=0xc000056f90 pc=0x4389d6
runtime.goparkunlock(...)
runtime/proc.go:387
runtime.forcegchelper()
runtime/proc.go:305 +0xb0 fp=0xc000056fe0 sp=0xc000056fb0 pc=0x438810
runtime.goexit()
runtime/asm_amd64.s:1598 +0x1 fp=0xc000056fe8 sp=0xc000056fe0 pc=0x467c61
created by runtime.init.6
runtime/proc.go:293 +0x25
goroutine 3 [GC sweep wait]:
runtime.gopark(0x1?, 0x0?, 0x0?, 0x0?, 0x0?)
runtime/proc.go:381 +0xd6 fp=0xc000057780 sp=0xc000057760 pc=0x4389d6
runtime.goparkunlock(...)
runtime/proc.go:387
runtime.bgsweep(0x0?)
runtime/mgcsweep.go:319 +0xde fp=0xc0000577c8 sp=0xc000057780 pc=0x42401e
runtime.gcenable.func1()
runtime/mgc.go:178 +0x26 fp=0xc0000577e0 sp=0xc0000577c8 pc=0x419286
runtime.goexit()
runtime/asm_amd64.s:1598 +0x1 fp=0xc0000577e8 sp=0xc0000577e0 pc=0x467c61
created by runtime.gcenable
runtime/mgc.go:178 +0x6b
goroutine 4 [GC scavenge wait]:
runtime.gopark(0xc000076000?, 0xec6988?, 0x0?, 0x0?, 0x0?)
runtime/proc.go:381 +0xd6 fp=0xc000057f70 sp=0xc000057f50 pc=0x4389d6
runtime.goparkunlock(...)
runtime/proc.go:387
runtime.(*scavengerState).park(0x13ff720)
runtime/mgcscavenge.go:400 +0x53 fp=0xc000057fa0 sp=0xc000057f70 pc=0x421ef3
runtime.bgscavenge(0x0?)
runtime/mgcscavenge.go:633 +0x65 fp=0xc000057fc8 sp=0xc000057fa0 pc=0x4224e5
runtime.gcenable.func2()
runtime/mgc.go:179 +0x26 fp=0xc000057fe0 sp=0xc000057fc8 pc=0x419226
runtime.goexit()
runtime/asm_amd64.s:1598 +0x1 fp=0xc000057fe8 sp=0xc000057fe0 pc=0x467c61
created by runtime.gcenable
runtime/mgc.go:179 +0xaa
goroutine 17 [finalizer wait]:
runtime.gopark(0x438d52?, 0x7a1622411148?, 0x0?, 0x0?, 0xc000056770?)
runtime/proc.go:381 +0xd6 fp=0xc000056628 sp=0xc000056608 pc=0x4389d6
runtime.runfinq()
runtime/mfinal.go:193 +0x107 fp=0xc0000567e0 sp=0xc000056628 pc=0x4182c7
runtime.goexit()
runtime/asm_amd64.s:1598 +0x1 fp=0xc0000567e8 sp=0xc0000567e0 pc=0x467c61
created by runtime.createfing
runtime/mfinal.go:163 +0x45
goroutine 18 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
runtime/proc.go:381 +0xd6 fp=0xc000052750 sp=0xc000052730 pc=0x4389d6
runtime.gcBgMarkWorker()
runtime/mgc.go:1275 +0xf1 fp=0xc0000527e0 sp=0xc000052750 pc=0x41aff1
runtime.goexit()
runtime/asm_amd64.s:1598 +0x1 fp=0xc0000527e8 sp=0xc0000527e0 pc=0x467c61
created by runtime.gcBgMarkStartWorkers
runtime/mgc.go:1199 +0x25
goroutine 33 [GC worker (idle)]:
runtime.gopark(0x1432600?, 0x3?, 0xf6?, 0xc6?, 0x0?)
runtime/proc.go:381 +0xd6 fp=0xc0000a2750 sp=0xc0000a2730 pc=0x4389d6
runtime.gcBgMarkWorker()
runtime/mgc.go:1275 +0xf1 fp=0xc0000a27e0 sp=0xc0000a2750 pc=0x41aff1
runtime.goexit()
runtime/asm_amd64.s:1598 +0x1 fp=0xc0000a27e8 sp=0xc0000a27e0 pc=0x467c61
created by runtime.gcBgMarkStartWorkers
runtime/mgc.go:1199 +0x25
goroutine 34 [GC worker (idle)]:
runtime.gopark(0x1432600?, 0x1?, 0x13?, 0xa6?, 0x0?)
runtime/proc.go:381 +0xd6 fp=0xc0000a2f50 sp=0xc0000a2f30 pc=0x4389d6
runtime.gcBgMarkWorker()
runtime/mgc.go:1275 +0xf1 fp=0xc0000a2fe0 sp=0xc0000a2f50 pc=0x41aff1
runtime.goexit()
runtime/asm_amd64.s:1598 +0x1 fp=0xc0000a2fe8 sp=0xc0000a2fe0 pc=0x467c61
created by runtime.gcBgMarkStartWorkers
runtime/mgc.go:1199 +0x25
goroutine 35 [GC worker (idle)]:
runtime.gopark(0x1432600?, 0x3?, 0x67?, 0x32?, 0x0?)
runtime/proc.go:381 +0xd6 fp=0xc0000a3750 sp=0xc0000a3730 pc=0x4389d6
runtime.gcBgMarkWorker()
runtime/mgc.go:1275 +0xf1 fp=0xc0000a37e0 sp=0xc0000a3750 pc=0x41aff1
runtime.goexit()
runtime/asm_amd64.s:1598 +0x1 fp=0xc0000a37e8 sp=0xc0000a37e0 pc=0x467c61
created by runtime.gcBgMarkStartWorkers
runtime/mgc.go:1199 +0x25
[exit status 2]
> ! stderr panic
FAIL: /tmp/testscript1266235343/panic.txtar/script.txtar:2: unexpected match for `panic` found in stderr: panic
error running panic.txtar in /tmp/testscript1266235343/panic.txtar
This issue reduces down to their being a panic when an empty JSON input is evaluated. @jpluscplusm - please can you update the description above to that minimal set of steps? The piping etc is not necessary to reproduce this.
This issue reduces down to their being a panic when an empty JSON input is evaluated. @jpluscplusm - please can you update the description above to that minimal set of steps? The piping etc is not necessary to reproduce this.
Done. Apologies for missing the simplicity of the repro!
Note that this is likely a duplicate of https://github.com/cue-lang/cue/issues/1790. The title talks about comments, but that panic happens with any YAML input containing no value at all.
Also noting that https://github.com/cue-lang/cue/issues/2721 is extremely similar too.
Validated that repro still fails under CUE v0.8.0
Note that this is likely a duplicate of #1790. The title talks about comments, but that panic happens with any YAML input containing no value at all.
Note that neither #1790 nor #2721 mention the fact that this issue applies to JSON files too (which actually triggers a slightly different panic backtrace), so this isn't a strict dupe.