@@ -3,6 +3,7 @@ package cmd
33import (
44 "encoding/json"
55 "fmt"
6+ "os"
67 "path/filepath"
78 "time"
89
@@ -15,7 +16,7 @@ import (
1516var AggregateResultsCmd = & cobra.Command {
1617 Use : "aggregate-results" ,
1718 Short : "Aggregate test results into a single JSON report" ,
18- RunE : func (cmd * cobra.Command , args []string ) error {
19+ Run : func (cmd * cobra.Command , args []string ) {
1920 fs := reports.OSFileSystem {}
2021
2122 // Get flag values
@@ -37,7 +38,8 @@ var AggregateResultsCmd = &cobra.Command{
3738
3839 // Ensure the output directory exists
3940 if err := fs .MkdirAll (outputDir , 0755 ); err != nil {
40- return fmt .Errorf ("error creating output directory: %w" , err )
41+ log .Error ().Err (err ).Str ("path" , outputDir ).Msg ("Error creating output directory" )
42+ os .Exit (ErrorExitCode )
4143 }
4244
4345 // Start spinner for loading test reports
@@ -59,16 +61,11 @@ var AggregateResultsCmd = &cobra.Command{
5961 if err != nil {
6062 s .Stop ()
6163 fmt .Println ()
62- return fmt .Errorf ("error loading test reports: %w" , err )
64+ log .Error ().Err (err ).Msg ("Error aggregating test reports" )
65+ os .Exit (ErrorExitCode )
6366 }
6467 s .Stop ()
6568 fmt .Println ()
66-
67- if err != nil {
68- s .Stop ()
69- return fmt .Errorf ("error aggregating test reports: %w" , err )
70- }
71- s .Stop ()
7269 log .Debug ().Msg ("Successfully loaded and aggregated test reports" )
7370
7471 // Start spinner for mapping test results to paths
@@ -80,9 +77,12 @@ var AggregateResultsCmd = &cobra.Command{
8077 err = reports .MapTestResultsToPaths (aggregatedReport , repoPath )
8178 if err != nil {
8279 s .Stop ()
83- return fmt .Errorf ("error mapping test results to paths: %w" , err )
80+ fmt .Println ()
81+ log .Error ().Err (err ).Msg ("Error mapping test results to paths" )
82+ os .Exit (ErrorExitCode )
8483 }
8584 s .Stop ()
85+ fmt .Println ()
8686 log .Debug ().Msg ("Successfully mapped paths to test results" )
8787
8888 // Map test results to code owners if codeOwnersPath is provided
@@ -94,16 +94,20 @@ var AggregateResultsCmd = &cobra.Command{
9494 err = reports .MapTestResultsToOwners (aggregatedReport , codeOwnersPath )
9595 if err != nil {
9696 s .Stop ()
97- return fmt .Errorf ("error mapping test results to code owners: %w" , err )
97+ fmt .Println ()
98+ log .Error ().Err (err ).Msg ("Error mapping test results to code owners" )
99+ os .Exit (ErrorExitCode )
98100 }
99101 s .Stop ()
102+ fmt .Println ()
100103 log .Debug ().Msg ("Successfully mapped code owners to test results" )
101104 }
102105
103106 failedTests := reports .FilterTests (aggregatedReport .Results , func (tr reports.TestResult ) bool {
104107 return ! tr .Skipped && tr .PassRatio < maxPassRatio
105108 })
106109 s .Stop ()
110+ fmt .Println ()
107111
108112 // Check if there are any failed tests
109113 if len (failedTests ) > 0 {
@@ -125,7 +129,8 @@ var AggregateResultsCmd = &cobra.Command{
125129 // Save the failed tests report with logs
126130 failedTestsReportWithLogsPath := filepath .Join (outputDir , "failed-test-results-with-logs.json" )
127131 if err := reports .SaveReport (fs , failedTestsReportWithLogsPath , * failedReportWithLogs ); err != nil {
128- return fmt .Errorf ("error saving failed tests report with logs: %w" , err )
132+ log .Error ().Err (err ).Msg ("Error saving failed tests report with logs" )
133+ os .Exit (ErrorExitCode )
129134 }
130135 log .Debug ().Str ("path" , failedTestsReportWithLogsPath ).Msg ("Failed tests report with logs saved" )
131136
@@ -139,7 +144,8 @@ var AggregateResultsCmd = &cobra.Command{
139144 // Save the failed tests report without logs
140145 failedTestsReportNoLogsPath := filepath .Join (outputDir , "failed-test-results.json" )
141146 if err := reports .SaveReport (fs , failedTestsReportNoLogsPath , * failedReportWithLogs ); err != nil {
142- return fmt .Errorf ("error saving failed tests report without logs: %w" , err )
147+ log .Error ().Err (err ).Msg ("Error saving failed tests report without logs" )
148+ os .Exit (ErrorExitCode )
143149 }
144150 log .Debug ().Str ("path" , failedTestsReportNoLogsPath ).Msg ("Failed tests report without logs saved" )
145151 } else {
@@ -156,7 +162,8 @@ var AggregateResultsCmd = &cobra.Command{
156162 // Save the aggregated report to the output directory
157163 aggregatedReportPath := filepath .Join (outputDir , "all-test-results.json" )
158164 if err := reports .SaveReport (fs , aggregatedReportPath , * aggregatedReport ); err != nil {
159- return fmt .Errorf ("error saving aggregated test report: %w" , err )
165+ log .Error ().Err (err ).Msg ("Error saving aggregated test report" )
166+ os .Exit (ErrorExitCode )
160167 }
161168 log .Debug ().Str ("path" , aggregatedReportPath ).Msg ("Aggregated test report saved" )
162169
@@ -171,14 +178,16 @@ var AggregateResultsCmd = &cobra.Command{
171178 err = generateAllTestsSummaryJSON (aggregatedReport , summaryFilePath , maxPassRatio )
172179 if err != nil {
173180 s .Stop ()
174- return fmt .Errorf ("error generating summary json: %w" , err )
181+ fmt .Println ()
182+ log .Error ().Err (err ).Msg ("Error generating summary json" )
183+ os .Exit (ErrorExitCode )
175184 }
176185 s .Stop ()
186+ fmt .Println ()
177187 log .Debug ().Str ("path" , summaryFilePath ).Msg ("Summary generated" )
178188 }
179189
180190 log .Info ().Str ("summary" , summaryFilePath ).Str ("report" , aggregatedReportPath ).Msg ("Aggregation complete" )
181- return nil
182191 },
183192}
184193
0 commit comments