adding duplicate key into map via an overlay should error before serialization time checks
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 167
- PR merge metrics
- No merged PRs in 30d
Description
### Steps to reproduce
1. template yml:
```
---
clients:
- client1:
secret: blah1
- client2:
secret: blah2
```
overlay.yml
```
#@ load("@ytt:overlay", "overlay")
#@overlay/match by=overlay.all
---
clients:
#@overlay/match by=overlay.all,expects="1+"
-
#@overlay/match by="secret", expects=0
client1:
secret: foo
```
2. ` ytt -f template.yml -f overlay.yml`
### Expected
A useful error message
### Actual
a go stack trace
```
error: panic: Unexpected duplicate key: client1
goroutine 1 [running]:
github.com/k14s/ytt/pkg/yamlmeta.convertToGo(0x99cac0, 0xc00017efa0, 0x0, 0xc000096728)
github.com/k14s/ytt@/pkg/yamlmeta/convert.go:65 +0x7de
github.com/k14s/ytt/pkg/yamlmeta.convertToGo(0x99c840, 0xc00017ed20, 0xc000073fb0, 0x0)
github.com/k14s/ytt@/pkg/yamlmeta/convert.go:74 +0x47e
github.com/k14s/ytt/pkg/yamlmeta.convertToGo(0x99cac0, 0xc00017e730, 0x7f46f377b6d0, 0x0)
github.com/k14s/ytt@/pkg/yamlmeta/convert.go:67 +0x5fd
github.com/k14s/ytt/pkg/yamlmeta.(*Document).AsYAMLBytes(0xc00017e3c0, 0x20, 0x952800, 0xc000199701, 0xc000159bc0, 0xc000199758)
github.com/k14s/ytt@/pkg/yamlmeta/document.go:25 +0x3c
github.com/k14s/ytt/pkg/yamlmeta.(*YAMLPrinter).Print(0xc000159bc0, 0xc00017e3c0, 0xb25800, 0xc000159bc0)
github.com/k14s/ytt@/pkg/yamlmeta/printers.go:36 +0x42
github.com/k14s/ytt/pkg/yamlmeta.(*DocumentSet).AsBytesWithPrinter(0xc000153110, 0xa91800, 0x1, 0x1, 0xc000096730, 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(0xc000199a68, 0xc00006f4c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
github.com/k14s/ytt@/pkg/workspace/library_loader.go:114
...
Truncated
...
```
Contributor guide
Research direction
Run the provided ytt command with the template and overlay, then start in pkg/yamlmeta/convert.go around line 65, where the duplicate-key panic occurs. Trace how workspace.LibraryLoader.Eval reaches serialization and verify that the reproduction reports a useful error instead of a Go stack trace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, yaml
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100