summaryrefslogtreecommitdiff
path: root/context.go
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-06-26 10:45:34 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-06-26 10:45:34 -0600
commit6000855c82fc1bdc5c256480b4161511f91ed703 (patch)
treebc1a7664021c9ebfa04b95c4d3ff63ca4da0c94f /context.go
parent38677aaa58eb76a416fa42146956f3e3a5981e75 (diff)
Fix panics by disallowing explicitly-defined null modules in config
Diffstat (limited to 'context.go')
-rw-r--r--context.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/context.go b/context.go
index 2af38ff..9661aca 100644
--- a/context.go
+++ b/context.go
@@ -100,6 +100,15 @@ func (ctx Context) LoadModule(name string, rawMsg json.RawMessage) (interface{},
}
}
+ if val == nil {
+ // returned module values are almost always type-asserted
+ // before being used, so a nil value would panic; and there
+ // is no good reason to explicitly declare null modules in
+ // a config; it might be because the user is trying to
+ // achieve a result they aren't expecting, which is a smell
+ return nil, fmt.Errorf("module value cannot be null")
+ }
+
if prov, ok := val.(Provisioner); ok {
err := prov.Provision(ctx)
if err != nil {