Yaml: remove empty-stream workaround in favor of go-yaml fix (#30789)

This commit is contained in:
andig 2026-06-14 11:00:54 +02:00 • committed by GitHub
parent 15aa800e65
commit 8f5983c189
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 15 additions and 36 deletions

View file

@ -1,8 +1,8 @@
package config
import (
"github.com/evcc-io/evcc/util/yaml"
"github.com/spf13/cast"
"go.yaml.in/yaml/v4"
)
// CustomDevice promotes an embedded yaml type to the top-level type

View file

@ -15,8 +15,8 @@ func TestYamlFloat(t *testing.T) {
func TestYamlEmpty(t *testing.T) {
var res map[string]any
err := yaml.Unmarshal([]byte(""), &res)
require.ErrorContains(t, err, "no documents in stream")
require.NoError(t, yaml.Unmarshal([]byte(""), &res))
require.Nil(t, res)
}
func TestYamlCommentsOnly(t *testing.T) {
@ -24,8 +24,8 @@ func TestYamlCommentsOnly(t *testing.T) {
# another comment
`
var res map[string]any
err := yaml.Unmarshal([]byte(b), &res)
require.ErrorContains(t, err, "no documents in stream")
require.NoError(t, yaml.Unmarshal([]byte(b), &res))
require.Nil(t, res)
}
func TestYamlError(t *testing.T) {

View file

@ -10,7 +10,7 @@ import (
"time"
"github.com/Masterminds/sprig/v3"
"github.com/evcc-io/evcc/util/yaml"
"go.yaml.in/yaml/v4"
)
func yamlQuote(value string) string {

View file

@ -6,7 +6,7 @@ import (
"os"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/yaml"
"go.yaml.in/yaml/v4"
)
// Instance is an actual instantiated template

View file

@ -1,20 +0,0 @@
package yaml
import (
"strings"
goyaml "go.yaml.in/yaml/v4"
)
func Marshal(data any) ([]byte, error) {
return goyaml.Marshal(data)
}
// Unmarshal invokes unmarshaler, ignoring empty document errors
func Unmarshal(b []byte, res any) error {
err := goyaml.Unmarshal(b, res)
if err != nil && strings.Contains(err.Error(), "no documents in stream") {
err = nil
}
return err
}