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

2
go.mod
View file

@ -104,7 +104,7 @@ require (
gitlab.com/bboehmke/sunny v0.17.0
go.bug.st/serial v1.7.1
go.uber.org/mock v0.6.0
go.yaml.in/yaml/v4 v4.0.0-rc.5
go.yaml.in/yaml/v4 v4.0.0-rc.5.0.20260613141257-7afcb0919cb5
golang.org/x/crypto v0.53.0
golang.org/x/crypto/x509roots/fallback v0.0.0-20260609182332-5f2de1a9f1e2
golang.org/x/exp v0.0.0-20260611194520-c48552f49976

4
go.sum
View file

@ -574,8 +574,8 @@ go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
go.yaml.in/yaml/v4 v4.0.0-rc.5 h1:JVliQq9EGOYaTgMi+k8BhUJyqcGk4ZqeuiN1Cirba9c=
go.yaml.in/yaml/v4 v4.0.0-rc.5/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
go.yaml.in/yaml/v4 v4.0.0-rc.5.0.20260613141257-7afcb0919cb5 h1:FN2nHSMZESIAuZHWbZPsqsduWNnLLMaJ3cVNojwa5pg=
go.yaml.in/yaml/v4 v4.0.0-rc.5.0.20260613141257-7afcb0919cb5/go.mod h1:aZqd9kCMsGL7AuUv/m/PvWLdg5sjJsZ4oHDEnfPPfY0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=

View file

@ -15,9 +15,8 @@ import (
"github.com/evcc-io/evcc/server/db"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/yaml"
"github.com/samber/lo"
goyaml "go.yaml.in/yaml/v4"
"go.yaml.in/yaml/v4"
"gorm.io/gorm"
)
@ -136,7 +135,7 @@ func SetJson(key string, val any) error {
func SetYaml(key string, val any) error {
var b bytes.Buffer
err := goyaml.NewEncoder(&b).Encode(val)
err := yaml.NewEncoder(&b).Encode(val)
if err == nil {
SetString(key, strings.TrimSpace(b.String()))
}

View file

@ -22,9 +22,9 @@ import (
"github.com/evcc-io/evcc/tariff"
"github.com/evcc-io/evcc/util/config"
"github.com/evcc-io/evcc/util/templates"
"github.com/evcc-io/evcc/util/yaml"
"github.com/evcc-io/evcc/vehicle"
"github.com/gorilla/mux"
"go.yaml.in/yaml/v4"
)
func devicesConfig[T any](class templates.Class, h config.Handler[T], hidePrivate bool) ([]map[string]any, error) {

View file

@ -16,9 +16,9 @@ import (
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/config"
"github.com/evcc-io/evcc/util/templates"
"github.com/evcc-io/evcc/util/yaml"
"github.com/go-viper/mapstructure/v2"
"github.com/samber/lo"
"go.yaml.in/yaml/v4"
)
const (

View file

@ -12,8 +12,8 @@ import (
"github.com/evcc-io/evcc/core/keys"
"github.com/evcc-io/evcc/server/db/settings"
"github.com/evcc-io/evcc/util/redact"
"github.com/evcc-io/evcc/util/yaml"
"github.com/gorilla/mux"
"go.yaml.in/yaml/v4"
)
func settingsGetStringHandler(key string) http.HandlerFunc {

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
}