carvel-dev / carvel-dev/ytt

improve error message when trying to put a docset into a document

Open
#212 4 comments 0 reactions 0 assignees View on GitHub
error msg improvement helping with an issue
Dominant language
Go
Stars
1.9k
Forks
167
PR merge metrics
No merged PRs in 30d

Description

Input:
```ytt
#@ def two_docs():
---
doc1
---
doc2
#@ end
#! dawg
--- #@ two_docs()
```
Panic:
```
error: panic: Unexpected docset value within document

goroutine 1 [running]:
github.com/k14s/ytt/pkg/yamlmeta.convertToGo(0x9a3800, 0xc000152540, 0x7f319fa216d0, 0x0)
github.com/k14s/ytt@/pkg/yamlmeta/convert.go:55 +0x734
github.com/k14s/ytt/pkg/yamlmeta.(*Document).AsYAMLBytes(0xc000164eb0, 0x20, 0x952800, 0xc00016d701, 0xc000176280, 0xc00016d758)
github.com/k14s/ytt@/pkg/yamlmeta/document.go:25 +0x3c
github.com/k14s/ytt/pkg/yamlmeta.(*YAMLPrinter).Print(0xc000176280, 0xc000164eb0, 0xb25800, 0xc000176280)
github.com/k14s/ytt@/pkg/yamlmeta/printers.go:36 +0x42
github.com/k14s/ytt/pkg/yamlmeta.(*DocumentSet).AsBytesWithPrinter(0xc0001524d0, 0xa91800, 0x1, 0x1, 0xc000094318, 0x1, 0x1)
github.com/k14s/ytt@/pkg/yamlmeta/document_set.go:58 +0xec
github.com/k14s/ytt/pkg/yamlmeta.(*DocumentSet).AsBytes(...)
github.com/k14s/ytt@/pkg/yamlmeta/document_set.go:43
github.com/k14s/ytt/pkg/workspace.(*LibraryLoader).Eval(0xc00016da68, 0xc00009b3c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
github.com/k14s/ytt@/pkg/workspace/library_loader.go:114 +0x33c
github.com/k14s/ytt/pkg/cmd/template.(*TemplateOptions).RunWithFiles(0xc0000b7540, 0xc000094118, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
github.com/k14s/ytt@/pkg/cmd/template/cmd.go:140 +0x4cd
github.com/k14s/ytt/pkg/cmd/template.(*TemplateOptions).Run(0xc0000b7540, 0x0, 0x0)
github.com/k14s/ytt@/pkg/cmd/template/cmd.go:92 +0x28b
github.com/k14s/ytt/pkg/cmd/template.NewCmd.func1(0xc0000d6dc0, 0xc000120e40, 0x0, 0x3, 0x0, 0x0)
github.com/k14s/ytt@/pkg/cmd/template/cmd.go:58 +0x2a
github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc0000d6dc0, 0xc000120e40, 0x0, 0x3, 0x0, 0x0)
github.com/cppforlife/cobrautil@v0.0.0-20200514214827-bb86e6965d72/misc.go:45 +0xaf
github.com/cppforlife/cobrautil.WrapRunEForCmd.func1.1(0xc0000d6dc0, 0xc000120e40, 0x0, 0x3, 0x0, 0x0)
github.com/cppforlife/cobrautil@v0.0.0-20200514214827-bb86e6965d72/misc.go:45 +0xaf
github.com/spf13/cobra.(*Command).execute(0xc0000d6dc0, 0xc00009a050, 0x3, 0x3, 0xc0000d6dc0, 0xc00009a050)
github.com/spf13/cobra@v1.0.0/command.go:842 +0x460
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000d6dc0, 0xc0000d6dc0, 0xe91480, 0xc0000a41f8)
github.com/spf13/cobra@v1.0.0/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
github.com/spf13/cobra@v1.0.0/command.go:887
main.main()
github.com/k14s/ytt@/cmd/ytt/ytt.go:21 +0x112

```

Reproducible with `ytt version 0.30.0` and whatever is currently running on [get-ytt.io](https://get-ytt.io/)

Contributor guide

Open the contributing guide

Research direction

Reproduce the input with ytt 0.30.0, then inspect pkg/yamlmeta/convert.go:55 and the callers shown in the stack trace, especially pkg/yamlmeta/document.go. Improve the panic into a useful error explaining the invalid docset placement, and verify that the same input reports the clearer error instead of a stack trace.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.