Skip to content

Commit aa19aaf

Browse files
authored
refactor(terraform): remove unused custom error (aquasecurity#6303)
1 parent 8fcef35 commit aa19aaf

File tree

1 file changed

+5
-33
lines changed

1 file changed

+5
-33
lines changed

pkg/iac/scanners/terraform/parser/load_module.go

+5-33
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package parser
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"io/fs"
87
"path"
@@ -14,15 +13,6 @@ import (
1413
"github.com/aquasecurity/trivy/pkg/iac/terraform"
1514
)
1615

17-
type moduleLoadError struct {
18-
source string
19-
err error
20-
}
21-
22-
func (m *moduleLoadError) Error() string {
23-
return fmt.Sprintf("failed to load module '%s': %s", m.source, m.err)
24-
}
25-
2616
type ModuleDefinition struct {
2717
Name string
2818
Path string
@@ -32,41 +22,23 @@ type ModuleDefinition struct {
3222
External bool
3323
}
3424

35-
// LoadModules reads all module blocks and loads the underlying modules, adding blocks to e.moduleBlocks
25+
// loadModules reads all module blocks and loads them
3626
func (e *evaluator) loadModules(ctx context.Context) []*ModuleDefinition {
37-
38-
blocks := e.blocks
39-
4027
var moduleDefinitions []*ModuleDefinition
4128

42-
expanded := e.expandBlocks(blocks.OfType("module"))
43-
44-
var loadErrors []*moduleLoadError
29+
expanded := e.expandBlocks(e.blocks.OfType("module"))
4530

4631
for _, moduleBlock := range expanded {
4732
if moduleBlock.Label() == "" {
4833
continue
4934
}
5035
moduleDefinition, err := e.loadModule(ctx, moduleBlock)
5136
if err != nil {
52-
var loadErr *moduleLoadError
53-
if errors.As(err, &loadErr) {
54-
var found bool
55-
for _, fm := range loadErrors {
56-
if fm.source == loadErr.source {
57-
found = true
58-
break
59-
}
60-
}
61-
if !found {
62-
loadErrors = append(loadErrors, loadErr)
63-
}
64-
continue
65-
}
66-
e.debug.Log("Failed to load module '%s'. Maybe try 'terraform init'?", err)
37+
e.debug.Log("Failed to load module %q. Maybe try 'terraform init'?", err)
6738
continue
6839
}
69-
e.debug.Log("Loaded module '%s' from '%s'.", moduleDefinition.Name, moduleDefinition.Path)
40+
41+
e.debug.Log("Loaded module %q from %q.", moduleDefinition.Name, moduleDefinition.Path)
7042
moduleDefinitions = append(moduleDefinitions, moduleDefinition)
7143
}
7244

0 commit comments

Comments
 (0)