Skip to content

Commit 235494a

Browse files
committed
Make sure that yaml is valid with gopkg.in/yaml.v3
The goccy library doesn't catch all the errors, that other libraries such as the one used by "yq" does. So check the yaml with both of them. Signed-off-by: Anders F Björklund <[email protected]>
1 parent 6b51e5d commit 235494a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ require (
3737
golang.org/x/sync v0.1.0
3838
golang.org/x/sys v0.7.0
3939
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473
40+
gopkg.in/yaml.v3 v3.0.1
4041
gotest.tools/v3 v3.4.0
4142
inet.af/tcpproxy v0.0.0-20220326234310-be3ee21c9fa0
4243
k8s.io/api v0.26.3
@@ -112,7 +113,6 @@ require (
112113
gopkg.in/inf.v0 v0.9.1 // indirect
113114
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
114115
gopkg.in/yaml.v2 v2.4.0 // indirect
115-
gopkg.in/yaml.v3 v3.0.1 // indirect
116116
gvisor.dev/gvisor v0.0.0-20221216231429-a78e892a26d2 // indirect
117117
k8s.io/klog/v2 v2.90.1 // indirect
118118
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect

pkg/limayaml/load.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ import (
1010
"github.com/lima-vm/lima/pkg/store/dirnames"
1111
"github.com/lima-vm/lima/pkg/store/filenames"
1212
"github.com/sirupsen/logrus"
13+
yamlv3 "gopkg.in/yaml.v3"
1314
)
1415

1516
func unmarshalYAML(data []byte, v interface{}, comment string) error {
1617
if err := yaml.UnmarshalWithOptions(data, v, yaml.DisallowDuplicateKey()); err != nil {
1718
return fmt.Errorf("failed to unmarshal YAML (%s): %w", comment, err)
1819
}
20+
// the go-yaml library doesn't catch all markup errors, unfortunately
21+
// make sure to get a "second opinion", using the same library as "yq"
22+
if err := yamlv3.Unmarshal(data, v); err != nil {
23+
return fmt.Errorf("failed to unmarshal YAML (%s): %w", comment, err)
24+
}
1925
if err := yaml.UnmarshalWithOptions(data, v, yaml.Strict()); err != nil {
2026
logrus.WithField("comment", comment).WithError(err).Warn("Non-strict YAML is deprecated and will be unsupported in a future version of Lima")
2127
// Non-strict YAML is known to be used by Rancher Desktop:

0 commit comments

Comments
 (0)