pelletier / go-toml

Go library for the TOML file format
https://github.com/pelletier/go-toml
Other
1.72k stars 209 forks source link

Improve error message for string parsing #858

Closed pgundlach closed 1 year ago

pgundlach commented 1 year ago

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

pgundlach commented 1 year ago

I guess this is a duplicate of https://github.com/pelletier/go-toml/issues/413#issuecomment-841651368

pelletier commented 1 year ago

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.