File tree Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Expand file tree Collapse file tree 3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ require (
37
37
golang.org/x/sync v0.1.0
38
38
golang.org/x/sys v0.7.0
39
39
gopkg.in/op/go-logging.v1 v1.0.0-20160211212156-b2cb9fa56473
40
+ gopkg.in/yaml.v3 v3.0.1
40
41
gotest.tools/v3 v3.4.0
41
42
inet.af/tcpproxy v0.0.0-20220326234310-be3ee21c9fa0
42
43
k8s.io/api v0.26.3
@@ -112,7 +113,6 @@ require (
112
113
gopkg.in/inf.v0 v0.9.1 // indirect
113
114
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
114
115
gopkg.in/yaml.v2 v2.4.0 // indirect
115
- gopkg.in/yaml.v3 v3.0.1 // indirect
116
116
gvisor.dev/gvisor v0.0.0-20221216231429-a78e892a26d2 // indirect
117
117
k8s.io/klog/v2 v2.90.1 // indirect
118
118
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
Original file line number Diff line number Diff line change @@ -10,12 +10,18 @@ import (
10
10
"github.com/lima-vm/lima/pkg/store/dirnames"
11
11
"github.com/lima-vm/lima/pkg/store/filenames"
12
12
"github.com/sirupsen/logrus"
13
+ yamlv3 "gopkg.in/yaml.v3"
13
14
)
14
15
15
16
func unmarshalYAML (data []byte , v interface {}, comment string ) error {
16
17
if err := yaml .UnmarshalWithOptions (data , v , yaml .DisallowDuplicateKey ()); err != nil {
17
18
return fmt .Errorf ("failed to unmarshal YAML (%s): %w" , comment , err )
18
19
}
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
+ }
19
25
if err := yaml .UnmarshalWithOptions (data , v , yaml .Strict ()); err != nil {
20
26
logrus .WithField ("comment" , comment ).WithError (err ).Warn ("Non-strict YAML is deprecated and will be unsupported in a future version of Lima" )
21
27
// Non-strict YAML is known to be used by Rancher Desktop:
Original file line number Diff line number Diff line change
1
+ package limayaml
2
+
3
+ import (
4
+ "testing"
5
+
6
+ "gotest.tools/v3/assert"
7
+ )
8
+
9
+ func TestLoadEmpty (t * testing.T ) {
10
+ _ , err := Load ([]byte {}, "empty.yaml" )
11
+ assert .NilError (t , err )
12
+ }
13
+
14
+ func TestLoadError (t * testing.T ) {
15
+ // missing a "script:" line
16
+ s := `
17
+ provision:
18
+ - mode: system
19
+ script: |
20
+ #!/bin/sh
21
+ echo one
22
+ - mode: system
23
+ #!/bin/sh
24
+ echo two
25
+ - mode: system
26
+ script: |
27
+ #!/bin/sh
28
+ echo three
29
+ `
30
+ _ , err := Load ([]byte (s ), "error.yaml" )
31
+ assert .ErrorContains (t , err , "failed to unmarshal YAML" )
32
+ }
You can’t perform that action at this time.
0 commit comments