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

Array of arrays cannot be written to disk #1132

Closed
greg-szabo opened this issue May 7, 2021 · 4 comments
Closed

Array of arrays cannot be written to disk #1132

greg-szabo opened this issue May 7, 2021 · 4 comments
Labels
kind/bug Something isn't working

Comments

@greg-szabo
Copy link

Expected behavior (what you expected to happen):

global-labels = [
    ["firstitem", "seconditem"],
]

After WriteConfig(), configuration written to disk.

Actual behavior (what actually happened):
File is empty, WriteConfig() returned with While marshaling config: cannot convert type []interface {} to Tree.

Note: this struct can be read from disk fine, it's only the writing that fails.

Repl.it link:
https://replit.com/@gregszabo/TOMLExample2

Code reproducing the issue:

package main

import (
	"bytes"
  "fmt"
	"github.com/spf13/viper"
)

func main() {

	var tomlExample = []byte(`
global-labels = [
    ["firstitem", "seconditem"],
]
`)

  viper.SetConfigFile("out.toml")
	viper.ReadConfig(bytes.NewBuffer(tomlExample))
  err := viper.WriteConfig()
  fmt.Printf("%v\n", err);
  // While marshaling config: cannot convert type []interface {} to Tree
  // "out.toml" is empty
}

Environment:

  • Viper version: v1.7.1
  • Config source: file
  • File format: TOML

Anything else we should know?:
The array is fine according to the TOML spec.

@greg-szabo greg-szabo added the kind/bug Something isn't working label May 7, 2021
@github-actions
Copy link

github-actions bot commented May 7, 2021

👋 Thanks for reporting!

A maintainer will take a look at your issue shortly. 👀

In the meantime: We are working on Viper v2 and we would love to hear your thoughts about what you like or don't like about Viper, so we can improve or fix those issues.

⏰ If you have a couple minutes, please take some time and share your thoughts: https://forms.gle/R6faU74qPRPAzchZ9

📣 If you've already given us your feedback, you can still help by spreading the news,
either by sharing the above link or telling people about this on Twitter:

https://twitter.com/sagikazarmark/status/1306904078967074816

Thank you! ❤️

@greg-szabo
Copy link
Author

Oh, goodie, I even wrote an example application for this one as requested to be able to easily reproduce the issue.

Happy anniversary random little bug.

@sagikazarmark
Copy link
Collaborator

@greg-szabo can you please check if this is still an issue with the latest version? Thanks!

@greg-szabo
Copy link
Author

Just checked, it works as expected now! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants