Merge lp:~jameinel/juju-core/1.18-panic-parsing-jenv-1312136 into lp:juju-core/1.18

Proposed by John A Meinel
Status: Merged
Merged at revision: 2275
Proposed branch: lp:~jameinel/juju-core/1.18-panic-parsing-jenv-1312136
Merge into: lp:juju-core/1.18
Diff against target: 61 lines (+27/-1)
3 files modified
juju/api.go (+6/-1)
juju/apiconn_test.go (+20/-0)
juju/export_test.go (+1/-0)
To merge this branch: bzr merge lp:~jameinel/juju-core/1.18-panic-parsing-jenv-1312136
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+217036@code.launchpad.net

Description of the change

juju/api.go: actually handle error (bug #1312136)

If there is a problem reading the .jenv file, it can return an error,
but we weren't paying attention to it. Instead we would end up getting a
panic() a few lines down when we go to use a *Config that is actually
nil.

This may not be perfect (because I wasn't seeing errors as I would
expect), but it is better than what we have.

https://codereview.appspot.com/92750043/

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

Reviewers: mp+217036_code.launchpad.net,

Message:
Please take a look.

Description:
juju/api.go: actually handle error (bug #1312136)

If there is a problem reading the .jenv file, it can return an error,
but we weren't paying attention to it. Instead we would end up getting a
panic() a few lines down when we go to use a *Config that is actually
nil.

This may not be perfect (because I wasn't seeing errors as I would
expect), but it is better than what we have.

https://code.launchpad.net/~jameinel/juju-core/1.18-panic-parsing-jenv-1312136/+merge/217036

(do not edit description out of merge proposal)

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

Affected files (+6, -0 lines):
   A [revision details]
   M juju/api.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-20140412095413-8rps4bhva01cu0o9
+New revision: <email address hidden>

Index: juju/api.go
=== modified file 'juju/api.go'
--- juju/api.go 2014-03-19 03:18:41 +0000
+++ juju/api.go 2014-04-24 12:13:52 +0000
@@ -259,6 +259,10 @@
   var err error
   if info != nil && len(info.BootstrapConfig()) > 0 {
    cfg, err = config.New(config.NoDefaults, info.BootstrapConfig())
+ if err != nil {
+ logger.Debugf("failed to parse BootstrapConfig(): %v", err)
+ return apiState{}, err
+ }
   } else if envs != nil {
    cfg, err = envs.Config(envName)
    if errors.IsNotFoundError(err) {

Revision history for this message
John A Meinel (jameinel) wrote :
Revision history for this message
Wayne Witzel III (wwitzel3) wrote :
Revision history for this message
Wayne Witzel III (wwitzel3) wrote :

Question

https://codereview.appspot.com/92750043/diff/20001/juju/api.go
File juju/api.go (right):

https://codereview.appspot.com/92750043/diff/20001/juju/api.go#newcode258
juju/api.go:258: var cfg *config.Config
What is the benefit of declaring these here? Instead of using := in the
config.New and envs.Config calls? It seems that declaring these here is
what prevents this being a compile time error (for unused err) instead
of a run time error for an unhandled panic?

https://codereview.appspot.com/92750043/

Revision history for this message
John A Meinel (jameinel) wrote :
Revision history for this message
John A Meinel (jameinel) wrote :
Revision history for this message
Wayne Witzel III (wwitzel3) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju/api.go'
2--- juju/api.go 2014-03-19 03:18:41 +0000
3+++ juju/api.go 2014-04-24 14:05:34 +0000
4@@ -256,10 +256,15 @@
5 // It returns nil if there was no configuration information found.
6 func apiConfigConnect(info configstore.EnvironInfo, envs *environs.Environs, envName string, stop <-chan struct{}, delay time.Duration) (apiState, error) {
7 var cfg *config.Config
8- var err error
9 if info != nil && len(info.BootstrapConfig()) > 0 {
10+ var err error
11 cfg, err = config.New(config.NoDefaults, info.BootstrapConfig())
12+ if err != nil {
13+ logger.Warningf("failed to parse bootstrap-config: %v", err)
14+ return apiState{}, err
15+ }
16 } else if envs != nil {
17+ var err error
18 cfg, err = envs.Config(envName)
19 if errors.IsNotFoundError(err) {
20 return apiState{}, err
21
22=== modified file 'juju/apiconn_test.go'
23--- juju/apiconn_test.go 2014-04-03 19:11:11 +0000
24+++ juju/apiconn_test.go 2014-04-24 14:05:34 +0000
25@@ -300,6 +300,26 @@
26 }
27 }
28
29+type badBootstrapInfo struct {
30+ configstore.EnvironInfo
31+}
32+
33+// BootstrapConfig is returned as a map with real content, but the content
34+// isn't actually valid configuration, causing config.New to fail
35+func (m *badBootstrapInfo) BootstrapConfig() map[string]interface{} {
36+ return map[string]interface{}{"something": "else"}
37+}
38+
39+func (s *NewAPIClientSuite) TestBadConfigDoesntPanic(c *gc.C) {
40+ stop := make(chan struct{})
41+ badInfo := &badBootstrapInfo{}
42+ _, err := juju.APIConfigConnect(badInfo, nil, "test", stop, 0)
43+ // The specific error we get depends on what key is invalid, which is a
44+ // bit spurious, but what we care about is that we didn't get a panic,
45+ // but instead got an error
46+ c.Assert(err, gc.ErrorMatches, ".*expected.*got nothing")
47+}
48+
49 func setEndpointAddress(c *gc.C, store configstore.Storage, envName string, addr string) {
50 // Populate the environment's info with an endpoint
51 // with a known address.
52
53=== modified file 'juju/export_test.go'
54--- juju/export_test.go 2014-03-19 03:18:41 +0000
55+++ juju/export_test.go 2014-04-24 14:05:34 +0000
56@@ -5,4 +5,5 @@
57 APIClose = &apiClose
58 ProviderConnectDelay = &providerConnectDelay
59 NewAPIFromStore = newAPIFromStore
60+ APIConfigConnect = apiConfigConnect
61 )

Subscribers

People subscribed via source and target branches

to all changes: