core: even more nil checks to catch missing objects
These are all things that ought to be present in normal use but can end up being nil in incorrect tests. Test debugging is simpler if these things return errors gracefully, rather than crashing.
This commit is contained in:
parent
26c1584317
commit
c82e3ec92f
|
@ -97,6 +97,10 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
provider := *n.Provider
|
provider := *n.Provider
|
||||||
providerSchema := *n.ProviderSchema
|
providerSchema := *n.ProviderSchema
|
||||||
|
|
||||||
|
if providerSchema == nil {
|
||||||
|
return nil, fmt.Errorf("provider schema is unavailable for %s", n.Addr)
|
||||||
|
}
|
||||||
|
|
||||||
var diags tfdiags.Diagnostics
|
var diags tfdiags.Diagnostics
|
||||||
|
|
||||||
// The provider and hook APIs still expect our legacy InstanceInfo type.
|
// The provider and hook APIs still expect our legacy InstanceInfo type.
|
||||||
|
|
|
@ -59,6 +59,9 @@ func (n *EvalConfigProvider) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
diags = diags.Append(err)
|
diags = diags.Append(err)
|
||||||
return nil, diags.NonFatalErr()
|
return nil, diags.NonFatalErr()
|
||||||
}
|
}
|
||||||
|
if schema == nil {
|
||||||
|
return nil, fmt.Errorf("schema not available for %s", n.Addr)
|
||||||
|
}
|
||||||
|
|
||||||
configSchema := schema.Provider
|
configSchema := schema.Provider
|
||||||
configBody := buildProviderConfig(ctx, n.Addr, config.Config)
|
configBody := buildProviderConfig(ctx, n.Addr, config.Config)
|
||||||
|
|
|
@ -30,6 +30,10 @@ type EvalReadDataDiff struct {
|
||||||
func (n *EvalReadDataDiff) Eval(ctx EvalContext) (interface{}, error) {
|
func (n *EvalReadDataDiff) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
// TODO: test
|
// TODO: test
|
||||||
|
|
||||||
|
if n.ProviderSchema == nil || *n.ProviderSchema == nil {
|
||||||
|
return nil, fmt.Errorf("provider schema not available for %s", n.Addr)
|
||||||
|
}
|
||||||
|
|
||||||
var diags tfdiags.Diagnostics
|
var diags tfdiags.Diagnostics
|
||||||
|
|
||||||
// The provider and hook APIs still expect our legacy InstanceInfo type.
|
// The provider and hook APIs still expect our legacy InstanceInfo type.
|
||||||
|
|
|
@ -83,6 +83,9 @@ func (n *EvalValidateProvider) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
diags = diags.Append(err)
|
diags = diags.Append(err)
|
||||||
return nil, diags.NonFatalErr()
|
return nil, diags.NonFatalErr()
|
||||||
}
|
}
|
||||||
|
if schema == nil {
|
||||||
|
return nil, fmt.Errorf("no schema is available for %s", n.Addr)
|
||||||
|
}
|
||||||
|
|
||||||
configSchema := schema.Provider
|
configSchema := schema.Provider
|
||||||
configBody := buildProviderConfig(ctx, n.Addr, config.Config)
|
configBody := buildProviderConfig(ctx, n.Addr, config.Config)
|
||||||
|
@ -319,7 +322,7 @@ type EvalValidateResource struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *EvalValidateResource) Eval(ctx EvalContext) (interface{}, error) {
|
func (n *EvalValidateResource) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
if n.ProviderSchema == nil {
|
if n.ProviderSchema == nil || *n.ProviderSchema == nil {
|
||||||
return nil, fmt.Errorf("EvalValidateResource has nil schema for %s", n.Addr)
|
return nil, fmt.Errorf("EvalValidateResource has nil schema for %s", n.Addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,8 +193,10 @@ func (n *NodeAbstractResource) References() []*addrs.Reference {
|
||||||
if p.When != configs.ProvisionerWhenCreate {
|
if p.When != configs.ProvisionerWhenCreate {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
refs, _ = lang.ReferencesInBlock(p.Connection.Config, connectionBlockSupersetSchema)
|
if p.Connection != nil {
|
||||||
result = append(result, refs...)
|
refs, _ = lang.ReferencesInBlock(p.Connection.Config, connectionBlockSupersetSchema)
|
||||||
|
result = append(result, refs...)
|
||||||
|
}
|
||||||
|
|
||||||
schema := n.ProvisionerSchemas[p.Type]
|
schema := n.ProvisionerSchemas[p.Type]
|
||||||
refs, _ = lang.ReferencesInBlock(p.Config, schema)
|
refs, _ = lang.ReferencesInBlock(p.Config, schema)
|
||||||
|
|
|
@ -83,7 +83,9 @@ func (n *NodeDestroyResourceInstance) References() []*addrs.Reference {
|
||||||
schema := n.ProvisionerSchemas[p.Type]
|
schema := n.ProvisionerSchemas[p.Type]
|
||||||
|
|
||||||
if p.When == configs.ProvisionerWhenDestroy {
|
if p.When == configs.ProvisionerWhenDestroy {
|
||||||
result = append(result, ReferencesFromConfig(p.Connection.Config, connectionBlockSupersetSchema)...)
|
if p.Connection != nil {
|
||||||
|
result = append(result, ReferencesFromConfig(p.Connection.Config, connectionBlockSupersetSchema)...)
|
||||||
|
}
|
||||||
result = append(result, ReferencesFromConfig(p.Config, schema)...)
|
result = append(result, ReferencesFromConfig(p.Config, schema)...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,9 @@ func testModule(t *testing.T, name string) *configs.Config {
|
||||||
// sources only this ultimately just records all of the module paths
|
// sources only this ultimately just records all of the module paths
|
||||||
// in a JSON file so that we can load them below.
|
// in a JSON file so that we can load them below.
|
||||||
diags := loader.InstallModules(dir, true, configload.InstallHooksImpl{})
|
diags := loader.InstallModules(dir, true, configload.InstallHooksImpl{})
|
||||||
t.Fatal(diags.Error())
|
if diags.HasErrors() {
|
||||||
|
t.Fatal(diags.Error())
|
||||||
|
}
|
||||||
|
|
||||||
config, diags := loader.LoadConfig(dir)
|
config, diags := loader.LoadConfig(dir)
|
||||||
if diags.HasErrors() {
|
if diags.HasErrors() {
|
||||||
|
|
Loading…
Reference in New Issue