Skip to content

Commit

Permalink
refactor(terraform): remove unused custom error (#6303)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikpivkin authored Mar 12, 2024
1 parent 8fcef35 commit aa19aaf
Showing 1 changed file with 5 additions and 33 deletions.
38 changes: 5 additions & 33 deletions pkg/iac/scanners/terraform/parser/load_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package parser

import (
"context"
"errors"
"fmt"
"io/fs"
"path"
Expand All @@ -14,15 +13,6 @@ import (
"github.com/aquasecurity/trivy/pkg/iac/terraform"
)

type moduleLoadError struct {
source string
err error
}

func (m *moduleLoadError) Error() string {
return fmt.Sprintf("failed to load module '%s': %s", m.source, m.err)
}

type ModuleDefinition struct {
Name string
Path string
Expand All @@ -32,41 +22,23 @@ type ModuleDefinition struct {
External bool
}

// LoadModules reads all module blocks and loads the underlying modules, adding blocks to e.moduleBlocks
// loadModules reads all module blocks and loads them
func (e *evaluator) loadModules(ctx context.Context) []*ModuleDefinition {

blocks := e.blocks

var moduleDefinitions []*ModuleDefinition

expanded := e.expandBlocks(blocks.OfType("module"))

var loadErrors []*moduleLoadError
expanded := e.expandBlocks(e.blocks.OfType("module"))

for _, moduleBlock := range expanded {
if moduleBlock.Label() == "" {
continue
}
moduleDefinition, err := e.loadModule(ctx, moduleBlock)
if err != nil {
var loadErr *moduleLoadError
if errors.As(err, &loadErr) {
var found bool
for _, fm := range loadErrors {
if fm.source == loadErr.source {
found = true
break
}
}
if !found {
loadErrors = append(loadErrors, loadErr)
}
continue
}
e.debug.Log("Failed to load module '%s'. Maybe try 'terraform init'?", err)
e.debug.Log("Failed to load module %q. Maybe try 'terraform init'?", err)
continue
}
e.debug.Log("Loaded module '%s' from '%s'.", moduleDefinition.Name, moduleDefinition.Path)

e.debug.Log("Loaded module %q from %q.", moduleDefinition.Name, moduleDefinition.Path)
moduleDefinitions = append(moduleDefinitions, moduleDefinition)
}

Expand Down

0 comments on commit aa19aaf

Please sign in to comment.