Keep failed processing reports consistent
This commit is contained in:
@@ -219,25 +219,34 @@ func (s *OutputSession) TranscriptPath() string {
|
||||
}
|
||||
|
||||
// Initialize publishes each initial report and attempts failed-status reports if any fail.
|
||||
func (s *OutputSession) Initialize(initial, failed ReportBundle) error {
|
||||
func (s *OutputSession) Initialize(initial ReportBundle, failed func([]FileFailure) ReportBundle) error {
|
||||
if s == nil || !s.enabled {
|
||||
return nil
|
||||
}
|
||||
var failures []error
|
||||
var failures []FileFailure
|
||||
for i, payload := range bundleParts(initial) {
|
||||
if err := s.replace(s.reports[i], payload); err != nil {
|
||||
failures = append(failures, FileFailure{Path: s.reports[i], Kind: "report initialization", Err: err})
|
||||
}
|
||||
}
|
||||
if len(failures) != 0 {
|
||||
for i, payload := range bundleParts(failed) {
|
||||
if len(failures) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := s.Close(); err != nil {
|
||||
failures = append(failures, FileFailure{Path: s.transcript, Kind: "output cleanup", Err: err})
|
||||
}
|
||||
if failed != nil {
|
||||
for i, payload := range bundleParts(failed(failures)) {
|
||||
if err := s.replace(s.reports[i], payload); err != nil {
|
||||
failures = append(failures, FileFailure{Path: s.reports[i], Kind: "failed report initialization", Err: err})
|
||||
}
|
||||
}
|
||||
failures = append(failures, s.Close())
|
||||
}
|
||||
return errors.Join(failures...)
|
||||
errs := make([]error, 0, len(failures))
|
||||
for _, failure := range failures {
|
||||
errs = append(errs, failure)
|
||||
}
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
// PrepareDebug creates optional initial diagnostics and returns any nonfatal problems.
|
||||
|
||||
@@ -121,7 +121,7 @@ func TestDisabledReportingIgnoresUnusableDirectory(t *testing.T) {
|
||||
if err != nil || len(session.ReportPaths()) != 0 {
|
||||
t.Fatalf("disabled reports probed: %+v %v", session, err)
|
||||
}
|
||||
if err := session.Initialize(ReportBundle{}, ReportBundle{}); err != nil {
|
||||
if err := session.Initialize(ReportBundle{}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "missing")); !errors.Is(err, os.ErrNotExist) {
|
||||
@@ -147,7 +147,7 @@ func TestStdoutModeInitializesAndFinalizesReports(t *testing.T) {
|
||||
}
|
||||
initial := ReportBundle{Errors: []byte("in progress errors"), Recoveries: []byte("in progress recoveries"), Markdown: []byte("in progress report")}
|
||||
finished := ReportBundle{Errors: []byte("completed errors"), Recoveries: []byte("completed recoveries"), Markdown: []byte("completed report")}
|
||||
if err := session.Initialize(initial, ReportBundle{}); err != nil {
|
||||
if err := session.Initialize(initial, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if session.TranscriptPath() != "" {
|
||||
@@ -184,7 +184,12 @@ func TestInitializeFailureMarksPriorReportFailedBeforeModelWork(t *testing.T) {
|
||||
return actual(path, payload)
|
||||
}
|
||||
modelCalled := false
|
||||
if err := session.Initialize(ReportBundle{Errors: []byte("initial"), Recoveries: []byte("initial"), Markdown: []byte("initial")}, ReportBundle{Errors: []byte("failed"), Recoveries: []byte("failed"), Markdown: []byte("failed")}); err == nil {
|
||||
if err := session.Initialize(ReportBundle{Errors: []byte("initial"), Recoveries: []byte("initial"), Markdown: []byte("initial")}, func(failures []FileFailure) ReportBundle {
|
||||
if len(failures) != 1 || filepath.Base(failures[0].Path) != RecoveriesFile {
|
||||
t.Fatalf("initialization failures: %+v", failures)
|
||||
}
|
||||
return ReportBundle{Errors: []byte("failed"), Recoveries: []byte("failed"), Markdown: []byte("failed")}
|
||||
}); err == nil {
|
||||
modelCalled = true
|
||||
}
|
||||
if modelCalled {
|
||||
@@ -206,7 +211,7 @@ func TestFinalizationCollectsFailuresAndRetainsPublishedTranscript(t *testing.T)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := session.Initialize(ReportBundle{Errors: []byte("initial"), Recoveries: []byte("initial"), Markdown: []byte("initial")}, ReportBundle{}); err != nil {
|
||||
if err := session.Initialize(ReportBundle{Errors: []byte("initial"), Recoveries: []byte("initial"), Markdown: []byte("initial")}, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
actual := session.replace
|
||||
|
||||
Reference in New Issue
Block a user