Merge lp:~mattyw/juju-core/1199432 into lp:~go-bot/juju-core/trunk

Proposed by Matthew Williams
Status: Merged
Approved by: William Reade
Approved revision: no longer in the source branch.
Merged at revision: 1498
Proposed branch: lp:~mattyw/juju-core/1199432
Merge into: lp:~go-bot/juju-core/trunk
Diff against target: 29 lines (+11/-0)
2 files modified
charm/config.go (+3/-0)
charm/config_test.go (+8/-0)
To merge this branch: bzr merge lp:~mattyw/juju-core/1199432
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+175856@code.launchpad.net

Commit message

Bug fix for lp:1199432

Currently an empty config supplied to charm.ReadConfig causes a panic, it would be better to return an error. lp:1199432

https://codereview.appspot.com/11542046/

Description of the change

Bug fix for lp:1199432

Currently an empty config supplied to charm.ReadConfig causes a panic, it would be better to return an error. lp:1199432

https://codereview.appspot.com/11542046/

To post a comment you must log in.
Revision history for this message
Matthew Williams (mattyw) wrote :

Reviewers: mp+175856_code.launchpad.net,

Message:
Please take a look.

Description:
Bug fix for lp:1199432

Currently an empty config supplied to charm.ReadConfig causes a panic,
it would be better to return an error. lp:1199432

https://code.launchpad.net/~mattyw/juju-core/1199432/+merge/175856

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/11542046/

Affected files:
   A [revision details]
   M charm/config.go
   M charm/config_test.go

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: tarmac-20130719095358-4z29gui2k03po34w
+New revision: <email address hidden>

Index: charm/config.go
=== modified file 'charm/config.go'
--- charm/config.go 2013-07-09 10:32:23 +0000
+++ charm/config.go 2013-07-19 14:49:06 +0000
@@ -102,6 +102,9 @@
   if err := goyaml.Unmarshal(data, &config); err != nil {
    return nil, err
   }
+ if config == nil {
+ return nil, fmt.Errorf("invalid config: empty configuration")
+ }
   for name, option := range config.Options {
    switch option.Type {
    case "string", "int", "float", "boolean":

Index: charm/config_test.go
=== modified file 'charm/config_test.go'
--- charm/config_test.go 2013-07-09 10:32:23 +0000
+++ charm/config_test.go 2013-07-19 14:49:06 +0000
@@ -403,3 +403,11 @@
   assertTypeError("float", "123", "123")
   assertTypeError("int", "true", "true")
  }
+
+// When an empty config is supplied an error should be returned
+func (s *ConfigSuite) TestEmptyConfigReturnsError(c *C) {
+ config := ""
+ result, err := charm.ReadConfig(bytes.NewBuffer([]byte(config)))
+ c.Assert(result, IsNil)
+ c.Assert(err, ErrorMatches, "invalid config: empty configuration")
+}

Revision history for this message
William Reade (fwereade) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charm/config.go'
2--- charm/config.go 2013-07-09 10:32:23 +0000
3+++ charm/config.go 2013-07-19 15:02:28 +0000
4@@ -102,6 +102,9 @@
5 if err := goyaml.Unmarshal(data, &config); err != nil {
6 return nil, err
7 }
8+ if config == nil {
9+ return nil, fmt.Errorf("invalid config: empty configuration")
10+ }
11 for name, option := range config.Options {
12 switch option.Type {
13 case "string", "int", "float", "boolean":
14
15=== modified file 'charm/config_test.go'
16--- charm/config_test.go 2013-07-09 10:32:23 +0000
17+++ charm/config_test.go 2013-07-19 15:02:28 +0000
18@@ -403,3 +403,11 @@
19 assertTypeError("float", "123", "123")
20 assertTypeError("int", "true", "true")
21 }
22+
23+// When an empty config is supplied an error should be returned
24+func (s *ConfigSuite) TestEmptyConfigReturnsError(c *C) {
25+ config := ""
26+ result, err := charm.ReadConfig(bytes.NewBuffer([]byte(config)))
27+ c.Assert(result, IsNil)
28+ c.Assert(err, ErrorMatches, "invalid config: empty configuration")
29+}

Subscribers

People subscribed via source and target branches

to status/vote changes: