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

Why does that return empty bytes? #960

Open
gabyx opened this issue Aug 7, 2024 · 1 comment
Open

Why does that return empty bytes? #960

gabyx opened this issue Aug 7, 2024 · 1 comment
Labels
question Question from a go-toml user.

Comments

@gabyx
Copy link

gabyx commented Aug 7, 2024

Describe the bug
A experienced empty bytes on a custom UnmarshalText type.

To Reproduce

package main

import (
	"fmt"

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

type C struct{}

func (c *C) UnmarshalText(bytes []byte) error {
	fmt.Printf("Bytes: %v", bytes)
	if len(bytes) == 0 {
		panic("why is this empty??")
	}
	return nil
}

type Steps struct {
	Config C
}

type Config struct {
	Steps Steps
}

func main() {
	file := `
[steps]
config = { a = "asfd" }
`
	c := Config{}
	err := toml.Unmarshal([]byte(file), &c)
	if err != nil {
		panic(err)
	}
}

Expected behavior

I expected the function UnmarshalText to not receive empty bytes.

Versions

  • go-toml: 2.2.2
  • go: 1.22.3
  • operating system: Linux
@pelletier
Copy link
Owner

Hi! The tom.TextUnmarshaler interface is only used when unmarshaling from a TOML string -- in your case it's an inline table. For example https://go.dev/play/p/oRPNRcnL5K-

I think what you want is similar to #873, but I don't think anyone has made progress on this in a while.

@pelletier pelletier added the question Question from a go-toml user. label Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question from a go-toml user.
Projects
None yet
Development

No branches or pull requests

2 participants