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

ast.Merge error cannot merge Mapping into Anchor #382

Open
rjshrjndrn opened this issue Jul 31, 2023 · 0 comments
Open

ast.Merge error cannot merge Mapping into Anchor #382

rjshrjndrn opened this issue Jul 31, 2023 · 0 comments

Comments

@rjshrjndrn
Copy link

rjshrjndrn commented Jul 31, 2023

Hi,

First of all, thank you for this amazing library.

I'm trying to merge 2 yamls, and getting error cannot merge Mapping into Anchor. I tried to search in the docs, and in repo to be in vein.

I'm getting started with golang. So can't crack very deep things 😬

Appreciate any help.

Code

package main

import (
	"fmt"
	"strings"

	"github.com/goccy/go-yaml"
	"github.com/goccy/go-yaml/parser"
)

func main() {
	original := `
chalice: &chalice
  env:
    environment: dev
    cloud: AWS
  other:
    - hey
    - hello
global:
  chalice: *chalice
	`
	override := `
chalice: &chalice
  env:
    environment: production
    jwt_enabled: false
global:
  chalice: *chalice
	`
	orig, err := parser.ParseBytes([]byte(original), 0)
	if err != nil {
		fmt.Println("panic")
		panic(err)
	}

	path, err := yaml.PathString("$.chalice")
	if err != nil {
		panic(err)
	}
	err = path.MergeFromReader(orig, strings.NewReader(override))
	if err != nil {
		panic(err)
	}
}

error

❯ go run main.go
panic: cannot merge Mapping into Anchor

goroutine 1 [running]:
main.main()
        /tmp/tmp_m/main.go:48 +0xc5
exit status 2
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

1 participant