Publish outputs to checked destinations and preserve failure evidence
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
@@ -43,7 +44,13 @@ func loadProcessInputs(ctx context.Context, input processInput, mode commandkit.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
raw, err := coreio.ReadRequiredFile(input.Transcript, "transcript")
|
||||
if ctx.Err() != nil {
|
||||
return nil, errors.Join(err, ctx.Err())
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -79,7 +86,10 @@ func prepareProcess(ctx context.Context, input processInput, loaded *processInpu
|
||||
if cfg.Reporting.Enabled {
|
||||
reportDir = cfg.Reporting.StdoutDir
|
||||
if input.Output.Value != "" && !reportDirSet {
|
||||
reportDir = filepath.Dir(input.Output.Value)
|
||||
reportDir, _ = filepath.Split(input.Output.Value)
|
||||
if reportDir == "" {
|
||||
reportDir = "."
|
||||
}
|
||||
}
|
||||
}
|
||||
runID, err := generateRunID()
|
||||
@@ -88,7 +98,7 @@ func prepareProcess(ctx context.Context, input processInput, loaded *processInpu
|
||||
}
|
||||
started := time.Now().UTC()
|
||||
var initial diagnostics.ReportBundle
|
||||
var failed func(error, []diagnostics.FileFailure) diagnostics.ReportBundle
|
||||
var failed diagnostics.ReportRenderer
|
||||
if cfg.Reporting.Enabled {
|
||||
snapshot := reporting.Snapshot{RunID: runID, Status: reporting.StatusInProgress, StartedAt: started, TranscriptPath: input.Transcript, OutputPath: input.Output.Value}
|
||||
for index, item := range cfg.Pipeline.Stages {
|
||||
@@ -98,15 +108,14 @@ func prepareProcess(ctx context.Context, input processInput, loaded *processInpu
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
failed = func(primary error, failures []diagnostics.FileFailure) diagnostics.ReportBundle {
|
||||
failed = func(primary error, failures []diagnostics.FileFailure) (diagnostics.ReportBundle, error) {
|
||||
failedSnapshot := snapshot
|
||||
completed := time.Now().UTC()
|
||||
failedSnapshot.CompletedAt = &completed
|
||||
if primary != nil {
|
||||
failedSnapshot.Errors = []reporting.ErrorRecord{{Scope: "run", Phase: "initialization", Reason: "canceled", Message: "Processing was canceled."}}
|
||||
}
|
||||
bundle, _ := renderReportBundle(failedOutputSnapshot(failedSnapshot, failures))
|
||||
return bundle
|
||||
return renderReportBundle(failedOutputSnapshot(failedSnapshot, failures))
|
||||
}
|
||||
}
|
||||
var debug *preflight.DebugInput
|
||||
|
||||
@@ -21,41 +21,22 @@ func finishProcess(inv commandkit.Invocation, input processInput, prepared *prep
|
||||
completed := time.Now().UTC()
|
||||
snapshot.RunID, snapshot.StartedAt, snapshot.CompletedAt = prepared.RunID, prepared.Started, &completed
|
||||
snapshot.TranscriptPath, snapshot.OutputPath = input.Transcript, input.Output.Value
|
||||
if primary == nil {
|
||||
primary = inv.Context.Err()
|
||||
}
|
||||
snapshot.Status = reporting.StatusCompleted
|
||||
if primary != nil {
|
||||
snapshot = failedProcessingSnapshot(snapshot, primary, inv.Context.Err())
|
||||
}
|
||||
reportPaths := prepared.Prepared.Output.ReportPaths()
|
||||
var reports diagnostics.ReportBundle
|
||||
var failed func([]diagnostics.FileFailure) diagnostics.ReportBundle
|
||||
var render diagnostics.ReportRenderer
|
||||
if len(reportPaths) > 0 {
|
||||
var err error
|
||||
reports, err = renderReportBundle(snapshot)
|
||||
if err != nil {
|
||||
if primary == nil {
|
||||
primary = err
|
||||
render = func(cause error, failures []diagnostics.FileFailure) (diagnostics.ReportBundle, error) {
|
||||
report := snapshot
|
||||
if cause != nil {
|
||||
report = failedProcessingSnapshot(report, cause, inv.Context.Err())
|
||||
}
|
||||
snapshot.Status = reporting.StatusFailed
|
||||
}
|
||||
failed = func(failures []diagnostics.FileFailure) diagnostics.ReportBundle {
|
||||
result, bundleErr := renderReportBundle(failedOutputSnapshot(snapshot, failures))
|
||||
if bundleErr != nil {
|
||||
return reports
|
||||
if len(failures) > 0 {
|
||||
report = failedOutputSnapshot(report, failures)
|
||||
}
|
||||
return result
|
||||
return renderReportBundle(report)
|
||||
}
|
||||
}
|
||||
if canceled := inv.Context.Err(); primary == nil && canceled != nil {
|
||||
primary = canceled
|
||||
snapshot = failedProcessingSnapshot(snapshot, canceled, canceled)
|
||||
if failed != nil {
|
||||
reports = failed(nil)
|
||||
}
|
||||
}
|
||||
result := prepared.Prepared.Output.Finish(primary, transcript, reports, failed)
|
||||
result := prepared.Prepared.Output.Finish(inv.Context, primary, transcript, render)
|
||||
if result != nil {
|
||||
return commandkit.Failure(result.Error()).WithCause(result)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user