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

Improve error message for string parsing #858

Closed
pgundlach opened this issue Mar 15, 2023 · 2 comments
Closed

Improve error message for string parsing #858

pgundlach opened this issue Mar 15, 2023 · 2 comments

Comments

@pgundlach
Copy link

Describe the bug
When I try to read foo = bar to a string, I get an error:

1| foo = bar
 |       ~~~ incomplete number

I think this error message might lead to confusion.

To Reproduce

package main

import (
	"fmt"

	"github.com/pelletier/go-toml/v2"
)

func main() {
	doc := `foo = bar`
	type mystruct struct {
		Foo string
	}
	var mydata mystruct

	err := toml.Unmarshal([]byte(doc), &mydata)
	fmt.Println(err.(*toml.DecodeError).String())

}

Expected behavior
Since the library knows what kind of data I expect (Foo is a string), I'd expect an error message such as "could not parse string" or "quotes missing" or something like that.

Versions

  • go-toml: github.com/pelletier/go-toml/v2 v2.0.7
  • go: go1.20.1
  • operating system: macOS
@pgundlach
Copy link
Author

I guess this is a duplicate of #413 (comment)

@pelletier
Copy link
Owner

You're right, that's a duplicate of #413. I'll close this one, but will add a note on the other issue that we should look into using the type of the target to generate an error message.

@pelletier pelletier closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2023
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