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

confused about using BURNTSUSHI_TOML_110 with os.Setenv() #394

Closed
notnmeyer opened this issue Jun 6, 2023 · 3 comments
Closed

confused about using BURNTSUSHI_TOML_110 with os.Setenv() #394

notnmeyer opened this issue Jun 6, 2023 · 3 comments

Comments

@notnmeyer
Copy link

notnmeyer commented Jun 6, 2023

I'm testing out the TOML 1.1 support that's available behind the flag in v1.3.0. the notes mention it can be enabled with either os.Setenv() or setting it explicitly on the command line.

the latter works, but the former doesn't and I'm questioning whether or not I'm misunderstanding it or doing something wrong.

here's a repro case,

package main

import (
        "os"
        "github.com/BurntSushi/toml"
)

type Config struct {
        blah map[string]string `toml:"blah"`
}

func main() {
        os.Setenv("BURNTSUSHI_TOML_110", "somevalue")

        tomlData := `blah = {
                foo = "bar",
        }`

        var conf Config
        _, err := toml.Decode(tomlData, &conf)
        if err != nil {
                panic(err)
        }
}

running this directly seem to be validating as TOML 1.0,

➜ go run main.go
panic: toml: line 1 (last key "blah"): newlines not allowed within inline tables

goroutine 1 [running]:
main.main()
        /var/folders/qm/fvys1tr11b7130r0zbbbzpx00000gn/T/tmp.sjsn2xa7/main.go:23 +0xd0
exit status 2

but this works,

➜ BURNTSUSHI_TOML_110=somevalue go run main.go; echo $status
0

am I misunderstanding what the release notes are suggesting about using os.Setenv()?

@arp242 arp242 closed this as completed in 96fcef2 Jun 6, 2023
@arp242
Copy link
Collaborator

arp242 commented Jun 6, 2023

The variable that sets this is a package-level variable: https://github.com/BurntSushi/toml/blob/60801d0/parse.go#L14

So this will get run as soon as the package is imported, and your os.Setenv("BURNTSUSHI_TOML_110", "somevalue") happens after that.

This is something I changed after I wrote the release note comment for this. It's kind of obvious that it won't work, but I did both things some weeks apart and it didn't really register 😅

I moved it back in the parse; sorry for the confusion.

@arp242
Copy link
Collaborator

arp242 commented Jun 6, 2023

I tagged v1.3.1 with a fix for this.

@notnmeyer
Copy link
Author

appreciate the explanation and fix :) cheers!

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