Skip to content

Commit

Permalink
core/runtime: panic if cueexperiment errors
Browse files Browse the repository at this point in the history
It was noticed that bad values of CUE_EXPERIMENT don't produce errors
when using the CUE Go public API. In particular, calls to
`cuecontext.New()` seem to work even with bad CUE_EXPERIMENTS. This was
found because a testscript had a typo:

```
env CUE_EXPERIMENT=evalv0=0
exec go run main.go
-- main.go --
package main
// some code that used cuecontext.New()
```

The cause is that in two places, we don't inspect the error from
`cueexperiment.Init()`. Because there is no nice error return path,
we instead panic.

Signed-off-by: Matthew Sackman <[email protected]>
Change-Id: I71a73775ee55085341c26f6c795c3db33b7b3da9
Dispatch-Trailer: {"type":"trybot","CL":1208729,"patchset":1,"ref":"refs/changes/29/1208729/1","targetBranch":"master"}
  • Loading branch information
cuematthew authored and cueckoo committed Feb 13, 2025
1 parent 6fb2a9b commit 6fdfaa7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion internal/core/runtime/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ var SharedRuntime = sync.OnceValue(func() *Runtime {
// but future evaluator versions may not be compatible at that level.
// We should consider using one SharedRuntime per evaluator version,
// or getting rid of SharedRuntime altogether.
cueexperiment.Init()
err := cueexperiment.Init()
if err != nil {
panic(err)
}
if cueexperiment.Flags.EvalV3 {
r.version = internal.DevVersion
} else {
Expand Down
5 changes: 4 additions & 1 deletion internal/core/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ func (r *Runtime) Init() {

r.loaded = map[*build.Instance]interface{}{}

cueexperiment.Init()
err := cueexperiment.Init()
if err != nil {
panic(err)
}
if cueexperiment.Flags.EvalV3 {
r.version = internal.DevVersion
} else {
Expand Down

0 comments on commit 6fdfaa7

Please sign in to comment.