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

UnmarshalText ignored in arrays #1006

Open
ainar-g opened this issue Nov 23, 2023 · 0 comments
Open

UnmarshalText ignored in arrays #1006

ainar-g opened this issue Nov 23, 2023 · 0 comments

Comments

@ainar-g
Copy link

ainar-g commented Nov 23, 2023

Code

package main

import (
	"encoding"
	"errors"
	"fmt"
	"log/slog"

	"gopkg.in/yaml.v3"
)

type obj struct {
	Values []value `yaml:"values"`
}

type value struct {
	param int
}

var _ encoding.TextUnmarshaler = (*value)(nil)

func (v *value) UnmarshalText(b []byte) (err error) {
	slog.Info("unmarshal", "b", b)

	return errors.New("unmarshal error")
}

const data = `
values:
  - a::
`

func main() {
	o := &obj{}
	err := yaml.Unmarshal([]byte(data), o)
	slog.Info("result", "err", err, "o", fmt.Sprintf("%#v", o))
}

Expected

The slog.Info in (*value).UnmarshalText to be called; an error.

Actual

2009/11/10 23:00:00 INFO result err=<nil> o=&main.obj{Values:[]main.value{main.value{param:0}}}

https://go.dev/play/p/1ucYRvnupUE

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

1 participant