ytt
ytt copied to clipboard
using multi document YAML fragments cause crash
The following example is causing a crash:
#@ def func1():
hello: world
---
new: document
#@ end
--- #@ func1()
The error:
- (p) expected to find node tag 1 when unwinding (backtrace: goroutine 1 [running]:
config.yml:3 in func1
L ---
config.yml:7 in <toplevel>
L --- #@ func1()
reason:
runtime/debug.Stack(0x8d80a0, 0x8a6240, 0xc000116610)
/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
github.com/k14s/ytt/pkg/template/core.ErrWrapper.func1.1(0xc00012e3f0)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/template/core/errs.go:20 +0x1c4
panic(0x8a6240, 0xc000116610)
/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/k14s/ytt/pkg/template.(*EvaluationCtx).unwindToTag(0xc000100690, 0x1)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/template/evaluation_ctx.go:237 +0x10d
github.com/k14s/ytt/pkg/template.(*EvaluationCtx).startNode(0xc000100690, 0x7, 0x7, 0x0)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/template/evaluation_ctx.go:189 +0x163
github.com/k14s/ytt/pkg/template.(*EvaluationCtx).TplStartNode(0xc000100690, 0xc0000e3050, 0xc0000e3170, 0xc000116600, 0x1, 0x1, 0x0, 0x0, 0x0, 0x8, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/template/evaluation_ctx.go:157 +0x179
github.com/k14s/ytt/pkg/template.(*CompiledTemplate).tplStartNode(...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/template/compiled_template.go:241
github.com/k14s/ytt/pkg/template/core.ErrWrapper.func1(0xc0000e3050, 0xc0000e3170, 0xc000116600, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/template/core/errs.go:25 +0xe9
github.com/k14s/ytt/vendor/go.starlark.net/starlark.(*Builtin).CallInternal(0xc0000e3170, 0xc0000e3050, 0xc000116600, 0x1, 0x1, 0x0, 0x0, 0x0, 0xc000116600, 0xdbfca0, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/go.starlark.net/starlark/value.go:622 +0x8b
github.com/k14s/ytt/vendor/go.starlark.net/starlark.Call(0xc0000e3050, 0xa8f7c0, 0xc0000e3170, 0xc000116600, 0x1, 0x1, 0x0, 0x0, 0x0, 0xa90080, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/go.starlark.net/starlark/eval.go:968 +0x154
github.com/k14s/ytt/vendor/go.starlark.net/starlark.call(0xc0000e3050, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0xc00012eb20, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/go.starlark.net/starlark/interp.go:292 +0x405a
github.com/k14s/ytt/vendor/go.starlark.net/starlark.(*Function).CallInternal(0xc000100620, 0xc0000e3050, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa90080, 0xdbfca0, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/go.starlark.net/starlark/interp.go:39 +0x1c1
github.com/k14s/ytt/vendor/go.starlark.net/starlark.Call(0xc0000e3050, 0xa8f840, 0xc000100620, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xa90080, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/go.starlark.net/starlark/eval.go:968 +0x154
github.com/k14s/ytt/vendor/go.starlark.net/starlark.call(0xc0000e3050, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x70, 0xc0001004d0, 0xc00012f240, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/go.starlark.net/starlark/interp.go:292 +0x405a
github.com/k14s/ytt/vendor/go.starlark.net/starlark.(*Function).CallInternal(0xc0001004d0, 0xc0000e3050, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x77c4b9, 0x9245a0, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/go.starlark.net/starlark/interp.go:39 +0x1c1
github.com/k14s/ytt/vendor/go.starlark.net/starlark.Call(0xc0000e3050, 0xa8f840, 0xc0001004d0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/go.starlark.net/starlark/eval.go:968 +0x154
github.com/k14s/ytt/vendor/go.starlark.net/starlark.(*Program).Init(0xc00000e240, 0xc0000e3050, 0xc0000e30b0, 0x0, 0x0, 0xc000066840)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/go.starlark.net/starlark/eval.go:340 +0x9a
github.com/k14s/ytt/pkg/template.(*CompiledTemplate).eval(0xc000066780, 0xc0000e3050, 0xc0000e30b0, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/template/compiled_template.go:140 +0x203
github.com/k14s/ytt/pkg/template.(*CompiledTemplate).Eval(0xc000066780, 0xc0000e3050, 0xa8e100, 0xc0000e27b0, 0xc0000e3050, 0xc0000e3020, 0xc0000d3f80, 0x0, 0x0)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/template/compiled_template.go:101 +0x719
github.com/k14s/ytt/pkg/workspace.(*TemplateLoader).EvalYAML(0xc0000e27b0, 0xc00001e460, 0xc0000628c0, 0xc000027328, 0xc0000e2780, 0x0, 0x0, 0x0)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/workspace/template_loader.go:160 +0x66d
github.com/k14s/ytt/pkg/cmd/template.(*TemplateOptions).RunWithFiles(0xc00009a2c0, 0xc00000e0d0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/cmd/template/cmd.go:109 +0xfef
github.com/k14s/ytt/pkg/cmd/template.(*TemplateOptions).Run(0xc00009a2c0, 0x0, 0x0)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/cmd/template/cmd.go:81 +0x292
github.com/k14s/ytt/pkg/cmd/template.NewCmd.func1(0xc000091680, 0xc0000e21e0, 0x0, 0x3, 0xb, 0xb)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/cmd/template/cmd.go:54 +0x2a
github.com/k14s/ytt/pkg/cmd.reconfigureLeafCmd.func1(0xc000091680, 0xc0000e21e0, 0x0, 0x3, 0x0, 0x0)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/pkg/cmd/ytt.go:90 +0x1b7
github.com/k14s/ytt/vendor/github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc000091680, 0xc0000e21e0, 0x0, 0x3, 0x0, 0x0)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/github.com/cppforlife/cobrautil/misc.go:25 +0xaf
github.com/k14s/ytt/vendor/github.com/spf13/cobra.(*Command).execute(0xc000091680, 0xc0000e21b0, 0x3, 0x3, 0xc000091680, 0xc0000e21b0)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/github.com/spf13/cobra/command.go:762 +0x465
github.com/k14s/ytt/vendor/github.com/spf13/cobra.(*Command).ExecuteC(0xc000091180, 0xc000091180, 0xdf47e0, 0xc000055f58)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/github.com/spf13/cobra/command.go:852 +0x2ec
github.com/k14s/ytt/vendor/github.com/spf13/cobra.(*Command).Execute(...)
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/vendor/github.com/spf13/cobra/command.go:800
main.main()
/Users/argonaut/workspace/k14s-go/src/github.com/k14s/ytt/cmd/ytt/ytt.go:17 +0x10b
)
here is way to do what's in your example:
#@ load("@ytt:template", "template")
#@ def func1():
---
hello: world
---
new: document
#@ end
--- #@ template.replace(func1())
what's happening is func1 spans chunk of first document, and then starts a new one. internal consistency checks catch it as a problem, though provide fairly cryptic error.
hello from 2022, this solution still works and is the first non carvel.dev google result for ytt multi document function
A reminder that this continues to be a rough edge for some number of folks. The desire to convert this from a panic to an error message (and provide a more approachable, actionable message) is still valuable. 👍🏻