2026-11-16 15:00:05 +00:00
|
|
|
package processreport
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"slices"
|
|
|
|
|
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/chunking"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/diagnostics"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/runner"
|
|
|
|
|
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/structuredoutput"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func processingFailure(cause error, phase string) RunFailure {
|
|
|
|
|
failure := RunFailure{Phase: phase, Reason: outcomes.ReasonInternalFailure}
|
|
|
|
|
var execution *runner.ExecutionFailure
|
|
|
|
|
if errors.As(cause, &execution) {
|
|
|
|
|
failure.Phase = execution.Phase
|
|
|
|
|
failure.Origin = execution.Origin
|
|
|
|
|
failure.HasSection = execution.HasSection
|
|
|
|
|
}
|
|
|
|
|
var model *structuredoutput.Failure
|
|
|
|
|
var infeasible *chunking.InfeasibleTargetError
|
|
|
|
|
switch {
|
2026-11-17 03:55:29 +00:00
|
|
|
case errors.As(cause, &model):
|
|
|
|
|
failure.Reason = model.EffectiveReason()
|
2026-11-16 15:00:05 +00:00
|
|
|
case errors.Is(cause, context.Canceled), errors.Is(cause, context.DeadlineExceeded):
|
|
|
|
|
failure.Reason = outcomes.ReasonCanceled
|
|
|
|
|
case errors.As(cause, &infeasible):
|
|
|
|
|
failure.Reason = outcomes.ReasonInputInvalid
|
|
|
|
|
case failure.Phase == "setup":
|
|
|
|
|
failure.Reason = outcomes.ReasonSetupFailure
|
|
|
|
|
}
|
|
|
|
|
return failure
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Failed publishes the primary processing failure once and adds delivery failures
|
|
|
|
|
// observed separately by the output session.
|
|
|
|
|
func Failed(snapshot reporting.Snapshot, primary error, phase string, files []diagnostics.FileFailure) reporting.Snapshot {
|
|
|
|
|
snapshot.Status = reporting.StatusFailed
|
|
|
|
|
snapshot.Errors = slices.Clone(snapshot.Errors)
|
|
|
|
|
count := 0
|
|
|
|
|
for _, record := range snapshot.Errors {
|
|
|
|
|
if record.Scope == "run" {
|
|
|
|
|
count++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if primary != nil && count == 0 {
|
|
|
|
|
snapshot.Errors = append(snapshot.Errors, failureRecord(processingFailure(primary, phase)))
|
|
|
|
|
count++
|
|
|
|
|
}
|
|
|
|
|
for _, file := range files {
|
|
|
|
|
record := failureRecord(RunFailure{Phase: string(file.Phase), Reason: "output_failure", OutputPath: file.Path})
|
|
|
|
|
if file.Phase == diagnostics.OutputInitialization {
|
|
|
|
|
record.Message = "Required report initialization failed."
|
|
|
|
|
}
|
|
|
|
|
snapshot.Errors = append(snapshot.Errors, record)
|
|
|
|
|
count++
|
|
|
|
|
}
|
|
|
|
|
snapshot.Summary.RunErrors = &count
|
|
|
|
|
return snapshot
|
|
|
|
|
}
|