Address most linting issues in tofu

Signed-off-by: Christian Mesh <christianmesh1@gmail.com>
This commit is contained in:
Christian Mesh
2025-03-12 12:09:37 -04:00
parent 5f1c049ba4
commit e00cf2f925
6 changed files with 22 additions and 6 deletions

View File

@@ -306,6 +306,7 @@ func (c *Context) watchStop(walker *ContextGraphWalker) (chan struct{}, <-chan s
// We ignore the error for now since there isn't any reasonable
// action to take if there is an error here, since the stop is still
// advisory: OpenTofu will exit once the graph node completes.
//nolint:errcheck
p.Stop()
}
}
@@ -323,6 +324,7 @@ func (c *Context) watchStop(walker *ContextGraphWalker) (chan struct{}, <-chan s
// We ignore the error for now since there isn't any reasonable
// action to take if there is an error here, since the stop is still
// advisory: OpenTofu will exit once the graph node completes.
//nolint:errcheck
p.Stop()
}
}

View File

@@ -1458,7 +1458,7 @@ output "out" {
_, diags = ctx.Plan(context.Background(), m, state, opts)
assertNoErrors(t, diags)
return
// TODO: unreachable code
//nolint:govet // TODO: unreachable code
otherProvider.ConfigureProviderCalled = false
otherProvider.ConfigureProviderFn = func(req providers.ConfigureProviderRequest) (resp providers.ConfigureProviderResponse) {
// check that our config is complete, even during a destroy plan

View File

@@ -88,7 +88,11 @@ func (cp *contextPlugins) ProviderSchema(addr addrs.Provider) (providers.Provide
if err != nil {
return schemas, fmt.Errorf("failed to instantiate provider %q to obtain schema: %w", addr, err)
}
defer provider.Close()
defer func() {
if err := provider.Close(); err != nil {
panic(err)
}
}()
resp := provider.GetProviderSchema()
if resp.Diagnostics.HasErrors() {
@@ -170,7 +174,11 @@ func (cp *contextPlugins) ProvisionerSchema(typ string) (*configschema.Block, er
if err != nil {
return nil, fmt.Errorf("failed to instantiate provisioner %q to obtain schema: %w", typ, err)
}
defer provisioner.Close()
defer func() {
if err := provisioner.Close(); err != nil {
panic(err)
}
}()
resp := provisioner.GetSchema()
if resp.Diagnostics.HasErrors() {

View File

@@ -110,7 +110,9 @@ func testModuleInline(t testing.TB, sources map[string]string) *configs.Config {
}
_, err = io.Copy(cfgF, strings.NewReader(configStr))
cfgF.Close()
if ferr := cfgF.Close(); ferr != nil {
t.Fatal(ferr)
}
if err != nil {
t.Fatalf("Error creating temporary file for config: %s", err)
}

View File

@@ -107,7 +107,9 @@ func (ctx *TestContext) evaluate(state *states.SyncState, changes *plans.Changes
defer func() {
for addr, inst := range providerInstances {
log.Printf("[INFO] Shutting down test provider %s", addr)
inst.Close()
if err := inst.Close(); err != nil {
log.Printf("[WARN] Unable to shut down provider %s in test context: %s", addr, err)
}
}
}()

View File

@@ -58,7 +58,9 @@ func TestModuleTransformAttachConfigTransformer(t *testing.T) {
for _, attr := range attrs {
val, _ := attr.Expr.Value(nil)
var target int
gocty.FromCtyValue(val, &target)
if err := gocty.FromCtyValue(val, &target); err != nil {
t.Fatal(err)
}
values[attr.Name] = target
}