diff --git a/pkg/cli/compile_command_test.go b/pkg/cli/compile_command_test.go index 7e1d3738b22..04c21e2b116 100644 --- a/pkg/cli/compile_command_test.go +++ b/pkg/cli/compile_command_test.go @@ -152,24 +152,29 @@ func TestTrackWorkflowFailure(t *testing.T) { name string workflowPath string errorCount int + errorMessages []string expectedDetails WorkflowFailure }{ { - name: "single error", - workflowPath: ".github/workflows/test.md", - errorCount: 1, + name: "single error", + workflowPath: ".github/workflows/test.md", + errorCount: 1, + errorMessages: []string{"test error message"}, expectedDetails: WorkflowFailure{ - Path: ".github/workflows/test.md", - ErrorCount: 1, + Path: ".github/workflows/test.md", + ErrorCount: 1, + ErrorMessages: []string{"test error message"}, }, }, { - name: "multiple errors", - workflowPath: ".github/workflows/complex.md", - errorCount: 5, + name: "multiple errors", + workflowPath: ".github/workflows/complex.md", + errorCount: 5, + errorMessages: []string{"error 1", "error 2"}, expectedDetails: WorkflowFailure{ - Path: ".github/workflows/complex.md", - ErrorCount: 5, + Path: ".github/workflows/complex.md", + ErrorCount: 5, + ErrorMessages: []string{"error 1", "error 2"}, }, }, } @@ -177,7 +182,7 @@ func TestTrackWorkflowFailure(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { stats := &CompilationStats{} - trackWorkflowFailure(stats, tt.workflowPath, tt.errorCount) + trackWorkflowFailure(stats, tt.workflowPath, tt.errorCount, tt.errorMessages) // Check that FailedWorkflows was updated if len(stats.FailedWorkflows) != 1 { @@ -196,6 +201,14 @@ func TestTrackWorkflowFailure(t *testing.T) { if detail.ErrorCount != tt.expectedDetails.ErrorCount { t.Errorf("Expected error count %d, got %d", tt.expectedDetails.ErrorCount, detail.ErrorCount) } + if len(detail.ErrorMessages) != len(tt.expectedDetails.ErrorMessages) { + t.Errorf("Expected %d error messages, got %d", len(tt.expectedDetails.ErrorMessages), len(detail.ErrorMessages)) + } + for i, msg := range detail.ErrorMessages { + if i < len(tt.expectedDetails.ErrorMessages) && msg != tt.expectedDetails.ErrorMessages[i] { + t.Errorf("Expected error message %q, got %q", tt.expectedDetails.ErrorMessages[i], msg) + } + } }) } } diff --git a/pkg/cli/compile_config.go b/pkg/cli/compile_config.go index 2ee7fc98ee1..9fa358deba9 100644 --- a/pkg/cli/compile_config.go +++ b/pkg/cli/compile_config.go @@ -37,8 +37,9 @@ type CompileConfig struct { // WorkflowFailure represents a failed workflow with its error count type WorkflowFailure struct { - Path string // File path of the workflow - ErrorCount int // Number of errors in this workflow + Path string // File path of the workflow + ErrorCount int // Number of errors in this workflow + ErrorMessages []string // Actual error messages to display to the user } // CompilationStats tracks the results of workflow compilation diff --git a/pkg/cli/compile_helpers.go b/pkg/cli/compile_helpers.go index b6176f86367..b81438af453 100644 --- a/pkg/cli/compile_helpers.go +++ b/pkg/cli/compile_helpers.go @@ -344,14 +344,15 @@ func handleFileDeleted(mdFile string, verbose bool) { } // trackWorkflowFailure adds a workflow failure to the compilation statistics -func trackWorkflowFailure(stats *CompilationStats, workflowPath string, errorCount int) { +func trackWorkflowFailure(stats *CompilationStats, workflowPath string, errorCount int, errorMessages []string) { // Add to FailedWorkflows for backward compatibility stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(workflowPath)) // Add detailed failure information stats.FailureDetails = append(stats.FailureDetails, WorkflowFailure{ - Path: workflowPath, - ErrorCount: errorCount, + Path: workflowPath, + ErrorCount: errorCount, + ErrorMessages: errorMessages, }) } @@ -367,15 +368,14 @@ func printCompilationSummary(stats *CompilationStats) { // Use different formatting based on whether there were errors if stats.Errors > 0 { fmt.Fprintln(os.Stderr, console.FormatErrorMessage(summary)) - // List the failed workflows with their error counts + // Display actual error messages from each failed workflow + // Error messages already include workflow path in format: file:line:col: error: message if len(stats.FailureDetails) > 0 { - fmt.Fprintln(os.Stderr, console.FormatErrorMessage("Failed workflows:")) for _, failure := range stats.FailureDetails { - errorWord := "error" - if failure.ErrorCount > 1 { - errorWord = "errors" + // Display the actual error messages for each failed workflow + for _, errMsg := range failure.ErrorMessages { + fmt.Fprintln(os.Stderr, errMsg) } - fmt.Fprintf(os.Stderr, " - %s (%d %s)\n", failure.Path, failure.ErrorCount, errorWord) } } else if len(stats.FailedWorkflows) > 0 { // Fallback for backward compatibility if FailureDetails is not populated diff --git a/pkg/cli/compile_orchestration.go b/pkg/cli/compile_orchestration.go index a93a0336f72..05d18c17b12 100644 --- a/pkg/cli/compile_orchestration.go +++ b/pkg/cli/compile_orchestration.go @@ -80,7 +80,7 @@ func compileSpecificFiles( errorMessages = append(errorMessages, err.Error()) errorCount++ stats.Errors++ - trackWorkflowFailure(stats, markdownFile, 1) + trackWorkflowFailure(stats, markdownFile, 1, []string{err.Error()}) result.Valid = false result.Errors = append(result.Errors, CompileValidationError{ Type: "resolution_error", @@ -104,8 +104,17 @@ func compileSpecificFiles( if !fileResult.success { errorCount++ stats.Errors++ - trackWorkflowFailure(stats, resolvedFile, 1) - errorMessages = append(errorMessages, fileResult.validationResult.Errors[0].Message) + // Collect error messages from validation result for display in summary + var errMsgs []string + for _, verr := range fileResult.validationResult.Errors { + errMsgs = append(errMsgs, verr.Message) + } + trackWorkflowFailure(stats, resolvedFile, 1, errMsgs) + // Only append first error to errorMessages for the return error value + // (all errors are already displayed in the summary via printCompilationSummary) + if len(fileResult.validationResult.Errors) > 0 { + errorMessages = append(errorMessages, fileResult.validationResult.Errors[0].Message) + } } else { compiledCount++ workflowDataList = append(workflowDataList, fileResult.workflowData) @@ -259,7 +268,12 @@ func compileAllFilesInDirectory( if !fileResult.success { errorCount++ stats.Errors++ - trackWorkflowFailure(stats, file, 1) + // Collect error messages from validation result + var errMsgs []string + for _, verr := range fileResult.validationResult.Errors { + errMsgs = append(errMsgs, verr.Message) + } + trackWorkflowFailure(stats, file, 1, errMsgs) } else { successCount++ workflowDataList = append(workflowDataList, fileResult.workflowData)