Keep failed processing reports consistent

This commit is contained in:
2026-11-10 20:16:59 +00:00
parent 3eacb33eb0
commit af0f9ac960
9 changed files with 115 additions and 41 deletions

View File

@@ -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.