go-toml icon indicating copy to clipboard operation
go-toml copied to clipboard

Missing quotes gives misleading error message

Open dckc opened this issue 5 years ago • 5 comments

Describe the bug The error message for missing quotes is misleading.

To Reproduce

  1. put something like timeout_broadcast_tx_commit = 20s in a .toml file
  2. start some utility that uses this library (such as cosmos-sdk)
  3. ERROR: While parsing config: (136, 33): parsing error: keys cannot contain new lines

Expected behavior ERROR: While parsing config: (136, 33): parsing error: value requires quotes or some such

Versions

  • go-toml: current, I think: 16c9a8b
  • go: go1.13.4.linux-amd64.tar.gz
  • operating system: Linux

Additional context see also https://github.com/cosmos/cosmos-sdk/issues/5165

dckc avatar May 23 '20 03:05 dckc

Thanks for reporting! I think it's a bug about the lexer when scanning integer type values

AllenX2018 avatar May 23 '20 09:05 AllenX2018

I wonder if it's specific to integer type values.

I got a similar error when quotes were missing from this line:

persistent_peers = [email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656

I'm not sure if the error message was the same. At some point while I was working on this, the error message was ERROR: While parsing config: invalid base.

But definitely in both cases, the solution was to add ""s around the value.

dckc avatar May 23 '20 15:05 dckc

It's not specific to integer types. I had:

host = builddb

and got the "keys cannot contain new line" error. This was corrected by correcting my config:

host = "builddb"

bjanders avatar May 06 '21 15:05 bjanders

Looks like that's still not great in v2: https://play.golang.org/p/9xauDfRSQI7

1| host = builddb
 |        ~~~~~~~ incomplete number


1| persistent_peers = [email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656
 |                     ~ expected newline but got U+0037 '7'

cc @vincentserpoul, on the topic of providing more meaningful errors.

pelletier avatar May 15 '21 12:05 pelletier

Good insight on #858: maybe we should consider passing the type of the target to provide a more accurate error.

pelletier avatar Mar 20 '23 18:03 pelletier