-
Notifications
You must be signed in to change notification settings - Fork 249
Open
Description
When evaluating the same file that has a syntax error in the same VM the second time the syntax error is swallowed and we get a panic.
This happens on v0.21.0 and the current master (10aef6a).
I have a fix: #823
Reproducable with:
input.jsonnet
'y';'z'
main.go
package main
import (
"fmt"
"github.com/google/go-jsonnet"
)
func main() {
vm := jsonnet.MakeVM()
// Has to be EvaluateFile; EvaluateAnonymousSnippet with the same
// contents doesn't crash (it would via an import).
f := func() (string, error) { return vm.EvaluateFile("input.jsonnet") }
fmt.Println(f())
// Crashes; the crucial bit here is that the VM is reused:
fmt.Println(f())
}
$ go run .
input.jsonnet:1:4-5 Did not expect: ";"
'y';'z'
INTERNAL ERROR: (CRASH) runtime error: invalid memory address or nil pointer dereference
goroutine 1 [running]:
runtime/debug.Stack()
/home/r/sdk/go1.25.2/src/runtime/debug/stack.go:26 +0x5e
github.com/google/go-jsonnet.(*VM).Evaluate.func1()
/home/r/go/pkg/mod/github.com/google/[email protected]/vm.go:187 +0x3d
panic({0x5bb860?, 0x786720?})
/home/r/sdk/go1.25.2/src/runtime/panic.go:783 +0x132
github.com/google/go-jsonnet.evaluateAux(0xc000034580, {0x0, 0x0}, 0xc000119a70)
/home/r/go/pkg/mod/github.com/google/[email protected]/interpreter.go:1325 +0x91
github.com/google/go-jsonnet.evaluate({0x0, 0x0}, 0xc000173e48?, 0xc000119a70, 0xc000119b60?, 0x0?, 0x5e9f73?, {0x650de0?, 0xc00006e028?}, 0x0, ...)
/home/r/go/pkg/mod/github.com/google/[email protected]/interpreter.go:1362 +0x91
github.com/google/go-jsonnet.(*VM).Evaluate(0xc000119b60?, {0x0?, 0x0?})
/home/r/go/pkg/mod/github.com/google/[email protected]/vm.go:190 +0xba
github.com/google/go-jsonnet.(*VM).EvaluateFile(0xc00015e230, {0x5e9f73?, 0xc000173f20?})
/home/r/go/pkg/mod/github.com/google/[email protected]/vm.go:419 +0xb4
main.main.func1(...)
/home/r/jsonnet-crash/main.go:13
main.main()
/home/r/jsonnet-crash/main.go:16 +0xc5
Please report a bug here: https://github.com/google/go-jsonnet/issues
Metadata
Metadata
Assignees
Labels
No labels