Skip to content

Why does that return empty bytes? #960

@gabyx

Description

@gabyx

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion from a go-toml user.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions