From 45b28d7299546cdf591e29e42889bfd69e0c76d4 Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Tue, 26 Jul 2022 15:26:24 -0400 Subject: [PATCH] Fixed dashboard and html-report command bugs (#104) Invalid files cause the app to crash, so this fixes that. I found this while tinkering in a pipeline. Signed-off-by: Dave Shanley --- cmd/dashboard.go | 5 +++++ cmd/html_report.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/cmd/dashboard.go b/cmd/dashboard.go index a9e5bbf1..a7712692 100644 --- a/cmd/dashboard.go +++ b/cmd/dashboard.go @@ -36,6 +36,10 @@ func GetDashboardCommand() *cobra.Command { var err error vacuumReport, specBytes, _ := vacuum_report.BuildVacuumReportFromFile(args[0]) + if len(specBytes) <= 0 { + pterm.Error.Printf("Failed to read specification: %v\n\n", args[0]) + return err + } var resultSet *model.RuleResultSet var ruleset *motor.RuleSetExecutionResult @@ -51,6 +55,7 @@ func GetDashboardCommand() *cobra.Command { rulesetFlag, _ := cmd.Flags().GetString("ruleset") resultSet, ruleset, err = BuildResults(rulesetFlag, specBytes, customFunctions) if err != nil { + pterm.Error.Printf("Failed to render dashboard: %v\n\n", err) return err } specIndex = ruleset.Index diff --git a/cmd/html_report.go b/cmd/html_report.go index 18b4d82e..eba92376 100644 --- a/cmd/html_report.go +++ b/cmd/html_report.go @@ -54,6 +54,10 @@ func GetHTMLReportCommand() *cobra.Command { start := time.Now() var err error vacuumReport, specBytes, _ := vacuum_report.BuildVacuumReportFromFile(args[0]) + if len(specBytes) <= 0 { + pterm.Error.Printf("Failed to read specification: %v\n\n", args[0]) + return err + } var resultSet *model.RuleResultSet var ruleset *motor.RuleSetExecutionResult @@ -70,10 +74,12 @@ func GetHTMLReportCommand() *cobra.Command { rulesetFlag, _ := cmd.Flags().GetString("ruleset") resultSet, ruleset, err = BuildResults(rulesetFlag, specBytes, customFunctions) if err != nil { + pterm.Error.Printf("Failed to generate report: %v\n\n", err) return err } specIndex = ruleset.Index specInfo = ruleset.SpecInfo + specInfo.Generated = time.Now() stats = statistics.CreateReportStatistics(specIndex, specInfo, resultSet)