Keep failed processing reports consistent
This commit is contained in:
@@ -23,8 +23,10 @@ func finishProcess(inv commandkit.Invocation, input processInput, loaded *proces
|
||||
snapshot.TranscriptPath, snapshot.OutputPath = input.Transcript, input.Output.Value
|
||||
if primary != nil {
|
||||
snapshot.Status = reporting.StatusFailed
|
||||
if len(snapshot.Errors) == 0 {
|
||||
snapshot.Errors = []reporting.ErrorRecord{{Scope: "run", Reason: "processing_failure", Message: "Processing failed"}}
|
||||
snapshot = failedOutputSnapshot(snapshot, nil)
|
||||
if *snapshot.Summary.RunErrors == 0 {
|
||||
snapshot.Errors = append(snapshot.Errors, reporting.ErrorRecord{Scope: "run", Reason: "processing_failure", Message: "Processing failed"})
|
||||
snapshot = failedOutputSnapshot(snapshot, nil)
|
||||
}
|
||||
} else {
|
||||
snapshot.Status = reporting.StatusCompleted
|
||||
@@ -37,13 +39,7 @@ func finishProcess(inv commandkit.Invocation, input processInput, loaded *proces
|
||||
snapshot.Status = reporting.StatusFailed
|
||||
}
|
||||
failed := func(failures []diagnostics.FileFailure) diagnostics.ReportBundle {
|
||||
copySnapshot := snapshot
|
||||
copySnapshot.Status = reporting.StatusFailed
|
||||
copySnapshot.Errors = append([]reporting.ErrorRecord(nil), snapshot.Errors...)
|
||||
for _, failure := range failures {
|
||||
copySnapshot.Errors = append(copySnapshot.Errors, reporting.ErrorRecord{Scope: "run", Reason: "output_failure", Message: "Required output delivery failed", OutputPath: failure.Path})
|
||||
}
|
||||
result, bundleErr := renderReportBundle(copySnapshot, secrets...)
|
||||
result, bundleErr := renderReportBundle(failedOutputSnapshot(snapshot, failures), secrets...)
|
||||
if bundleErr != nil {
|
||||
return reports
|
||||
}
|
||||
@@ -63,3 +59,27 @@ func finishProcess(inv commandkit.Invocation, input processInput, loaded *proces
|
||||
}
|
||||
return commandkit.Success()
|
||||
}
|
||||
|
||||
// failedOutputSnapshot derives the count from the same run records sent to each report.
|
||||
func failedOutputSnapshot(snapshot reporting.Snapshot, failures []diagnostics.FileFailure) reporting.Snapshot {
|
||||
snapshot.Status = reporting.StatusFailed
|
||||
if len(failures) > 0 {
|
||||
snapshot.Errors = append([]reporting.ErrorRecord(nil), snapshot.Errors...)
|
||||
}
|
||||
for _, failure := range failures {
|
||||
record := reporting.ErrorRecord{Scope: "run", Reason: "output_failure", Message: "Required output delivery failed", OutputPath: failure.Path}
|
||||
if failure.Kind == "report initialization" {
|
||||
record.Phase = "initialization"
|
||||
record.Message = "Required report initialization failed"
|
||||
}
|
||||
snapshot.Errors = append(snapshot.Errors, record)
|
||||
}
|
||||
count := 0
|
||||
for _, record := range snapshot.Errors {
|
||||
if record.Scope == "run" {
|
||||
count++
|
||||
}
|
||||
}
|
||||
snapshot.Summary.RunErrors = &count
|
||||
return snapshot
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user