@@ -2,7 +2,6 @@ package parser
2
2
3
3
import (
4
4
"context"
5
- "errors"
6
5
"fmt"
7
6
"io/fs"
8
7
"path"
@@ -14,15 +13,6 @@ import (
14
13
"github.com/aquasecurity/trivy/pkg/iac/terraform"
15
14
)
16
15
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
-
26
16
type ModuleDefinition struct {
27
17
Name string
28
18
Path string
@@ -32,41 +22,23 @@ type ModuleDefinition struct {
32
22
External bool
33
23
}
34
24
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
36
26
func (e * evaluator ) loadModules (ctx context.Context ) []* ModuleDefinition {
37
-
38
- blocks := e .blocks
39
-
40
27
var moduleDefinitions []* ModuleDefinition
41
28
42
- expanded := e .expandBlocks (blocks .OfType ("module" ))
43
-
44
- var loadErrors []* moduleLoadError
29
+ expanded := e .expandBlocks (e .blocks .OfType ("module" ))
45
30
46
31
for _ , moduleBlock := range expanded {
47
32
if moduleBlock .Label () == "" {
48
33
continue
49
34
}
50
35
moduleDefinition , err := e .loadModule (ctx , moduleBlock )
51
36
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 )
67
38
continue
68
39
}
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 )
70
42
moduleDefinitions = append (moduleDefinitions , moduleDefinition )
71
43
}
72
44
0 commit comments