Skip to content

Commit

Permalink
aws-dump: Print errors to the log
Browse files Browse the repository at this point in the history
  • Loading branch information
hamstah committed Aug 2, 2019
1 parent 033da19 commit cb5cd2f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions aws/dump/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ func worker(id int, jobs <-chan Job, results chan<- *ReportResult) {
}
}

func Run(jobs []Job) []Resource {
resources := []Resource{}

func Run(jobs []Job) ([]Resource, []error) {
jobsChan := make(chan Job, len(jobs))
results := make(chan *ReportResult, len(jobs))

Expand All @@ -117,11 +115,15 @@ func Run(jobs []Job) []Resource {
}
close(jobsChan)

resources := []Resource{}
errors := []error{}
for i := 0; i < len(jobs); i++ {
result := <-results
if result.Error == nil {
resources = append(resources, result.Resources...)
} else {
errors = append(errors, result.Error)
}
}
return resources
return resources, errors
}
7 changes: 6 additions & 1 deletion aws/dump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/hamstah/awstools/common"
log "github.com/sirupsen/logrus"

kingpin "gopkg.in/alecthomas/kingpin.v2"
)
Expand Down Expand Up @@ -70,7 +71,7 @@ func main() {
}
}

resources := Run(jobs)
resources, errors := Run(jobs)

report := []Resource{}
if *terraformBackendConfig != "" {
Expand Down Expand Up @@ -102,6 +103,10 @@ func main() {
report = resources
}

for _, err := range errors {
log.Error(err)
}

reportJSON, err := json.MarshalIndent(report, "", " ")
common.FatalOnError(err)

Expand Down

0 comments on commit cb5cd2f

Please sign in to comment.