Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while merging anchors #918

Closed
AbrahamTewa opened this issue Nov 2, 2022 · 4 comments
Closed

Error while merging anchors #918

AbrahamTewa opened this issue Nov 2, 2022 · 4 comments

Comments

@AbrahamTewa
Copy link

AbrahamTewa commented Nov 2, 2022

Hi !

I have an error when I try to unmarshall YAML with merging anchors:

package main

import (
	"log"

	yaml "gopkg.in/yaml.v3"
)

var data = `
anchorA: &anchorA
  A: 1

  anchorB: &anchorB
  B: 2

testFinal:
  <<: *anchorA
  <<: *anchorB
`

func main() {
	m := make(map[interface{}]interface{})

	err := yaml.Unmarshal([]byte(data), &m)
	log.Fatalf("error: %v", err)
}

I get an error:

error: yaml: unmarshal errors:
  line 10: mapping key "<<" already defined at line 9
@perlpunk
Copy link

perlpunk commented Nov 2, 2022

try this:

testFinal:
  <<: [*anchorA, *anchorB]

@AbrahamTewa
Copy link
Author

This syntax seems to work (no errors).

@AbrahamTewa
Copy link
Author

Hi !
Any update on this issue ?

Thanks !

@perlpunk
Copy link

I wouldn't expect an update. My suggestion is the official way to merge multiple anchors, see https://yaml.org/type/merge.html

go-yaml's behaviour is not a bug. You better rewrite your YAML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants