Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Conversation

@lukemassa
Copy link

I was originally confused by the fact that this code produced an error:

	var test struct{}
	err := yaml.NewDecoder(bytes.NewReader([]byte(""))).Decode(&test)
	fmt.Println(test, err)

whereas this did not:

	var test struct{}
	err := yaml.Unmarshal([]byte(""), &test)
	fmt.Println(test, err)

See: https://go.dev/play/p/tM_jp90fjFx

However, when I looked closer, I realized that this was the intended behavior. Decode() decodes the "next" document until it can't find any more, which it then indicates via io.EOF. If it were to return nil, there'd be no way for the client of Decode() to know there were no more documents.

This change adds to the documentation so this is a bit clearer.

Closes: #805

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reading empty file causes Decode to return error

2 participants