Skip to content

Commit ab43451

Browse files
authored
Fix error messages not shown in gh aw compile output (#14901)
1 parent 53c6ad2 commit ab43451

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed

pkg/cli/compile_command_test.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,32 +152,37 @@ func TestTrackWorkflowFailure(t *testing.T) {
152152
name string
153153
workflowPath string
154154
errorCount int
155+
errorMessages []string
155156
expectedDetails WorkflowFailure
156157
}{
157158
{
158-
name: "single error",
159-
workflowPath: ".github/workflows/test.md",
160-
errorCount: 1,
159+
name: "single error",
160+
workflowPath: ".github/workflows/test.md",
161+
errorCount: 1,
162+
errorMessages: []string{"test error message"},
161163
expectedDetails: WorkflowFailure{
162-
Path: ".github/workflows/test.md",
163-
ErrorCount: 1,
164+
Path: ".github/workflows/test.md",
165+
ErrorCount: 1,
166+
ErrorMessages: []string{"test error message"},
164167
},
165168
},
166169
{
167-
name: "multiple errors",
168-
workflowPath: ".github/workflows/complex.md",
169-
errorCount: 5,
170+
name: "multiple errors",
171+
workflowPath: ".github/workflows/complex.md",
172+
errorCount: 5,
173+
errorMessages: []string{"error 1", "error 2"},
170174
expectedDetails: WorkflowFailure{
171-
Path: ".github/workflows/complex.md",
172-
ErrorCount: 5,
175+
Path: ".github/workflows/complex.md",
176+
ErrorCount: 5,
177+
ErrorMessages: []string{"error 1", "error 2"},
173178
},
174179
},
175180
}
176181

177182
for _, tt := range tests {
178183
t.Run(tt.name, func(t *testing.T) {
179184
stats := &CompilationStats{}
180-
trackWorkflowFailure(stats, tt.workflowPath, tt.errorCount)
185+
trackWorkflowFailure(stats, tt.workflowPath, tt.errorCount, tt.errorMessages)
181186

182187
// Check that FailedWorkflows was updated
183188
if len(stats.FailedWorkflows) != 1 {
@@ -196,6 +201,14 @@ func TestTrackWorkflowFailure(t *testing.T) {
196201
if detail.ErrorCount != tt.expectedDetails.ErrorCount {
197202
t.Errorf("Expected error count %d, got %d", tt.expectedDetails.ErrorCount, detail.ErrorCount)
198203
}
204+
if len(detail.ErrorMessages) != len(tt.expectedDetails.ErrorMessages) {
205+
t.Errorf("Expected %d error messages, got %d", len(tt.expectedDetails.ErrorMessages), len(detail.ErrorMessages))
206+
}
207+
for i, msg := range detail.ErrorMessages {
208+
if i < len(tt.expectedDetails.ErrorMessages) && msg != tt.expectedDetails.ErrorMessages[i] {
209+
t.Errorf("Expected error message %q, got %q", tt.expectedDetails.ErrorMessages[i], msg)
210+
}
211+
}
199212
})
200213
}
201214
}

pkg/cli/compile_config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ type CompileConfig struct {
3737

3838
// WorkflowFailure represents a failed workflow with its error count
3939
type WorkflowFailure struct {
40-
Path string // File path of the workflow
41-
ErrorCount int // Number of errors in this workflow
40+
Path string // File path of the workflow
41+
ErrorCount int // Number of errors in this workflow
42+
ErrorMessages []string // Actual error messages to display to the user
4243
}
4344

4445
// CompilationStats tracks the results of workflow compilation

pkg/cli/compile_helpers.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,15 @@ func handleFileDeleted(mdFile string, verbose bool) {
344344
}
345345

346346
// trackWorkflowFailure adds a workflow failure to the compilation statistics
347-
func trackWorkflowFailure(stats *CompilationStats, workflowPath string, errorCount int) {
347+
func trackWorkflowFailure(stats *CompilationStats, workflowPath string, errorCount int, errorMessages []string) {
348348
// Add to FailedWorkflows for backward compatibility
349349
stats.FailedWorkflows = append(stats.FailedWorkflows, filepath.Base(workflowPath))
350350

351351
// Add detailed failure information
352352
stats.FailureDetails = append(stats.FailureDetails, WorkflowFailure{
353-
Path: workflowPath,
354-
ErrorCount: errorCount,
353+
Path: workflowPath,
354+
ErrorCount: errorCount,
355+
ErrorMessages: errorMessages,
355356
})
356357
}
357358

@@ -367,15 +368,14 @@ func printCompilationSummary(stats *CompilationStats) {
367368
// Use different formatting based on whether there were errors
368369
if stats.Errors > 0 {
369370
fmt.Fprintln(os.Stderr, console.FormatErrorMessage(summary))
370-
// List the failed workflows with their error counts
371+
// Display actual error messages from each failed workflow
372+
// Error messages already include workflow path in format: file:line:col: error: message
371373
if len(stats.FailureDetails) > 0 {
372-
fmt.Fprintln(os.Stderr, console.FormatErrorMessage("Failed workflows:"))
373374
for _, failure := range stats.FailureDetails {
374-
errorWord := "error"
375-
if failure.ErrorCount > 1 {
376-
errorWord = "errors"
375+
// Display the actual error messages for each failed workflow
376+
for _, errMsg := range failure.ErrorMessages {
377+
fmt.Fprintln(os.Stderr, errMsg)
377378
}
378-
fmt.Fprintf(os.Stderr, " - %s (%d %s)\n", failure.Path, failure.ErrorCount, errorWord)
379379
}
380380
} else if len(stats.FailedWorkflows) > 0 {
381381
// Fallback for backward compatibility if FailureDetails is not populated

pkg/cli/compile_orchestration.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func compileSpecificFiles(
8080
errorMessages = append(errorMessages, err.Error())
8181
errorCount++
8282
stats.Errors++
83-
trackWorkflowFailure(stats, markdownFile, 1)
83+
trackWorkflowFailure(stats, markdownFile, 1, []string{err.Error()})
8484
result.Valid = false
8585
result.Errors = append(result.Errors, CompileValidationError{
8686
Type: "resolution_error",
@@ -104,8 +104,17 @@ func compileSpecificFiles(
104104
if !fileResult.success {
105105
errorCount++
106106
stats.Errors++
107-
trackWorkflowFailure(stats, resolvedFile, 1)
108-
errorMessages = append(errorMessages, fileResult.validationResult.Errors[0].Message)
107+
// Collect error messages from validation result for display in summary
108+
var errMsgs []string
109+
for _, verr := range fileResult.validationResult.Errors {
110+
errMsgs = append(errMsgs, verr.Message)
111+
}
112+
trackWorkflowFailure(stats, resolvedFile, 1, errMsgs)
113+
// Only append first error to errorMessages for the return error value
114+
// (all errors are already displayed in the summary via printCompilationSummary)
115+
if len(fileResult.validationResult.Errors) > 0 {
116+
errorMessages = append(errorMessages, fileResult.validationResult.Errors[0].Message)
117+
}
109118
} else {
110119
compiledCount++
111120
workflowDataList = append(workflowDataList, fileResult.workflowData)
@@ -259,7 +268,12 @@ func compileAllFilesInDirectory(
259268
if !fileResult.success {
260269
errorCount++
261270
stats.Errors++
262-
trackWorkflowFailure(stats, file, 1)
271+
// Collect error messages from validation result
272+
var errMsgs []string
273+
for _, verr := range fileResult.validationResult.Errors {
274+
errMsgs = append(errMsgs, verr.Message)
275+
}
276+
trackWorkflowFailure(stats, file, 1, errMsgs)
263277
} else {
264278
successCount++
265279
workflowDataList = append(workflowDataList, fileResult.workflowData)

0 commit comments

Comments
 (0)