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

Intermittent error when loading in from a reader #108

Closed
mike182uk opened this issue Nov 8, 2016 · 1 comment
Closed

Intermittent error when loading in from a reader #108

mike182uk opened this issue Nov 8, 2016 · 1 comment

Comments

@mike182uk
Copy link

mike182uk commented Nov 8, 2016

Hey,

I came across this when having the problem i reported in #107

Using the following:

package main

import (
	"fmt"
	"strings"
	toml "github.com/pelletier/go-toml"
)

func main(){
	var m1 = map[string]interface{}{
		"foo": 1,
		"bar": "baz",
		"qux": map[string]interface{}{
			"foo": 1,
			"bar": "baz",
		},
		"foobar": true,
	}

	// generate a tree from m1, then convert to a string

	tree := toml.TreeFromMap(m1)
	r := strings.NewReader(tree.ToString())

	// load in the generated toml string

	toml, err := toml.LoadReader(r)

	if err != nil {
		panic(err)
	}

	// convert to a map

	tmap := toml.ToMap()

	// debug

	fmt.Print(tree.ToString())
	fmt.Println(tmap)
}

Most of the time everything would work correctly, but occasionally i would get an error:

panic: (6, 1): The following key was defined twice: qux.foo

goroutine 1 [running]:
panic(0xe4160, 0xc42000af20)
        /usr/local/Cellar/go/1.7.3/libexec/src/runtime/panic.go:500 +0x1a1
main.main()

Again, i'm not sure if it's down to how i am using the library or if theres something going wrong somewhere else. Any ideas?

@pelletier
Copy link
Owner

Thank you for your feedback! :)

I believe this is exactly #107, as depending on the map's order, ToString ends up generating sometimes

bar = "Baz"
foo = 1
foobar = true
[qux]
foo = 1
bar = "baz"

which works, but sometimes

bar = "Baz"
foobar = true
[qux]
foo = 1
bar = "baz"
foo = 1

which would trigger the panic you're seeing.

I'm closing this issue to track the work on #107.

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