diff options
| author | Samuele Pedroni <pedronis@lucediurna.net> | 2019-08-16 12:28:23 +0200 |
|---|---|---|
| committer | Samuele Pedroni <pedronis@lucediurna.net> | 2019-08-16 12:28:23 +0200 |
| commit | b5a460499b0ef85c84e8761d88498375efd74d8f (patch) | |
| tree | 640afdc52e8f2e0119ddeadea3ec26afc8de823f /snap | |
| parent | ead1285793dfdada68697650d23236ca08bfe1fe (diff) | |
clarify that the attribute key (not value) has unexpected type
or is empty
Diffstat (limited to 'snap')
| -rw-r--r-- | snap/info_snap_yaml.go | 4 | ||||
| -rw-r--r-- | snap/info_snap_yaml_test.go | 26 |
2 files changed, 27 insertions, 3 deletions
diff --git a/snap/info_snap_yaml.go b/snap/info_snap_yaml.go index cab8dfdf07..bb5a7c63b7 100644 --- a/snap/info_snap_yaml.go +++ b/snap/info_snap_yaml.go @@ -606,7 +606,7 @@ func convertToSlotOrPlugData(plugOrSlot, name string, data interface{}) (iface, for keyData, valueData := range data.(map[interface{}]interface{}) { key, ok := keyData.(string) if !ok { - err := fmt.Errorf("%s %q has attribute that is not a string (found %T)", + err := fmt.Errorf("%s %q has attribute key that is not a string (found %T)", plugOrSlot, name, keyData) return "", "", nil, err } @@ -615,6 +615,8 @@ func convertToSlotOrPlugData(plugOrSlot, name string, data interface{}) (iface, return "", "", nil, err } switch key { + case "": + return "", "", nil, fmt.Errorf("%s %q has an empty attribute key", plugOrSlot, name) case "interface": value, ok := valueData.(string) if !ok { diff --git a/snap/info_snap_yaml_test.go b/snap/info_snap_yaml_test.go index f8f8570186..a9cfd0557d 100644 --- a/snap/info_snap_yaml_test.go +++ b/snap/info_snap_yaml_test.go @@ -441,7 +441,18 @@ plugs: net: 1: ok `)) - c.Assert(err, ErrorMatches, `plug "net" has attribute that is not a string \(found int\)`) + c.Assert(err, ErrorMatches, `plug "net" has attribute key that is not a string \(found int\)`) +} + +func (s *YamlSuite) TestUnmarshalCorruptedPlugWithEmptyAttributeKey(c *C) { + // NOTE: yaml content cannot use tabs, indent the section with spaces. + _, err := snap.InfoFromSnapYaml([]byte(` +name: snap +plugs: + net: + "": ok +`)) + c.Assert(err, ErrorMatches, `plug "net" has an empty attribute key`) } func (s *YamlSuite) TestUnmarshalCorruptedPlugWithUnexpectedType(c *C) { @@ -854,7 +865,18 @@ slots: net: 1: ok `)) - c.Assert(err, ErrorMatches, `slot "net" has attribute that is not a string \(found int\)`) + c.Assert(err, ErrorMatches, `slot "net" has attribute key that is not a string \(found int\)`) +} + +func (s *YamlSuite) TestUnmarshalCorruptedSlotWithEmptyAttributeKey(c *C) { + // NOTE: yaml content cannot use tabs, indent the section with spaces. + _, err := snap.InfoFromSnapYaml([]byte(` +name: snap +slots: + net: + "": ok +`)) + c.Assert(err, ErrorMatches, `slot "net" has an empty attribute key`) } func (s *YamlSuite) TestUnmarshalCorruptedSlotWithUnexpectedType(c *C) { |
