Restore cancellation checks before report delivery

This commit is contained in:
2026-10-26 14:32:03 +00:00
parent 13a4d4eacd
commit de2266af75
9 changed files with 193 additions and 57 deletions

View File

@@ -2,6 +2,7 @@ package ckconfig
import (
"fmt"
"io"
commandkit "gitea.maximumdirect.net/eric/CommandKit"
)
@@ -74,3 +75,26 @@ func configAcquisitionFailure(
message := fmt.Sprintf("Unable to %s configuration scope %q.", operation, scope)
return configFailure(message, acquired.Explanation, cause)
}
// Preserve the preparation/delivery cancellation checkpoint for buffered reports.
func renderPreparedConfigReport(invocation commandkit.Invocation, explanation commandkit.Explanation, prepare func() ([]byte, error)) commandkit.Outcome {
var canceled error
renderErr := invocation.Reporter().RenderOutput(func(writer io.Writer) error {
report, err := prepare()
if err != nil {
return err
}
if canceled = invocation.Context.Err(); canceled != nil {
return nil
}
_, err = writer.Write(report)
return err
})
if canceled == nil && renderErr != nil {
canceled = invocation.Context.Err()
}
if canceled != nil {
return configFailure("Configuration report preparation was canceled.", explanation, canceled)
}
return commandkit.Success()
}