cue
cue copied to clipboard
encoding/jsonschema: panic when importing an empty object
What version of CUE are you using (cue version)?
cue version v0.5.0-beta.5
go version go1.19.3
-compiler gc
-trimpath true
CGO_ENABLED 0
GOARCH amd64
GOOS linux
GOAMD64 v1
Does this issue reproduce with the latest stable release?
Yes (0.4.3)
What did you do?
I imported a JSONSchema file that contains a schema constraining an object to be empty. CUE panicked:
exec cue import jsonschema: schema.json
-- schema.json --
{
"description": "an empty object",
"type": "object",
"properties": {},
"additionalProperties": false
}
What did you expect to see?
I expected to see some CUE output that declared and/or constrained the field to be {}. Ideally with a close() around it, due to the additionalProperties: false, but I'm aware that question is tracked in #750.
Removing the additionalProperties: false field stops the panic, but results in an output which is literally just ..., which IMHO is precisely the /opposite/ of the output that I believe the JSONSchema is representing.
What did you see instead?
> exec cue import jsonschema: schema.json
[stderr]
panic: runtime error: index out of range [0] with length 0 [recovered]
panic: runtime error: index out of range [0] with length 0
goroutine 1 [running]:
cuelang.org/go/cmd/cue/cmd.recoverError(0xc00030fe90)
cuelang.org/[email protected]/cmd/cue/cmd/root.go:261 +0x7b
panic({0xbf2e00, 0xc00003e258})
runtime/panic.go:884 +0x212
cuelang.org/go/encoding/jsonschema.(*decoder).schema(0xc0000f1a40, {0x0, 0x0, 0x698900?}, {0xc00034e690?, 0xc0000f8ab0?, 0x0?})
cuelang.org/[email protected]/encoding/jsonschema/decode.go:153 +0xedb
cuelang.org/go/encoding/jsonschema.(*decoder).decode(0xc0000f1a40, {0xc00034e690?, 0xc0000f8ab0?, 0x0?})
cuelang.org/[email protected]/encoding/jsonschema/decode.go:73 +0x23f
cuelang.org/go/encoding/jsonschema.Extract({0xd74718, 0xc000395110}, 0xc0000f57c0)
cuelang.org/[email protected]/encoding/jsonschema/jsonschema.go:47 +0x9e
cuelang.org/go/internal/encoding.jsonSchemaFunc.func1(0xc00034e690?)
cuelang.org/[email protected]/internal/encoding/encoding.go:301 +0x199
cuelang.org/go/internal/encoding.(*Decoder).doInterpret(0xc0000f8990)
cuelang.org/[email protected]/internal/encoding/encoding.go:114 +0x1ac
cuelang.org/go/internal/encoding.(*Decoder).Next(0xc0000f8990)
cuelang.org/[email protected]/internal/encoding/encoding.go:93 +0xc9
cuelang.org/go/internal/encoding.NewDecoder(0xc000394d90, 0xde0000c000012010?)
cuelang.org/[email protected]/internal/encoding/encoding.go:246 +0xda5
cuelang.org/go/cmd/cue/cmd.(*buildPlan).getDecoders(0xc0002e05b0, 0xc00024c1e0)
cuelang.org/[email protected]/cmd/cue/cmd/common.go:476 +0x585
cuelang.org/go/cmd/cue/cmd.parseArgs(0xc0002b6ff0, {0xc0002b3340, 0x2, 0x2}, 0xc0002c2c30)
cuelang.org/[email protected]/cmd/cue/cmd/common.go:566 +0x69c
cuelang.org/go/cmd/cue/cmd.runImport(0xc0002b6ff0?, {0xc0002b3340, 0x2, 0x2})
cuelang.org/[email protected]/cmd/cue/cmd/import.go:315 +0x96a
cuelang.org/go/cmd/cue/cmd.mkRunE.func1(0xc0002da780?, {0xc0002b3340, 0x2, 0x2})
cuelang.org/[email protected]/cmd/cue/cmd/root.go:72 +0xb3
github.com/spf13/cobra.(*Command).execute(0xc0002da780, {0xc0002b32e0, 0x2, 0x2})
github.com/spf13/[email protected]/command.go:856 +0x67c
github.com/spf13/cobra.(*Command).ExecuteC(0xc0002c6c80)
github.com/spf13/[email protected]/command.go:974 +0x3bd
github.com/spf13/cobra.(*Command).Execute(...)
github.com/spf13/[email protected]/command.go:902
cuelang.org/go/cmd/cue/cmd.(*Command).Run(0xc0002b6ff0, {0x3?, 0x3?})
cuelang.org/[email protected]/cmd/cue/cmd/root.go:246 +0x6b
cuelang.org/go/cmd/cue/cmd.mainErr({0xd79070, 0xc00003a090}, {0xc000034090?, 0x60?, 0x11ee380?})
cuelang.org/[email protected]/cmd/cue/cmd/root.go:183 +0x55
cuelang.org/go/cmd/cue/cmd.Main()
cuelang.org/[email protected]/cmd/cue/cmd/root.go:165 +0x7c
main.main()
cuelang.org/[email protected]/cmd/cue/main.go:24 +0x19
[exit status 2]
FAIL: /tmp/testscript609928878/panic.txtar/script.txtar:1: unexpected command failure
error running panic.txtar in /tmp/testscript609928878/panic.txtar
Thanks for the report, @jpluscplusm
cc @rogpeppe