Skip to content

Commit

Permalink
Merge pull request #318 from atc0005/extend-logging-for-error-collect…
Browse files Browse the repository at this point in the history
…ion-handling-dev-branch

Extend logging for error collection handling
  • Loading branch information
atc0005 authored Nov 22, 2024
2 parents 336f305 + a05b657 commit 4b18424
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sections.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ func (p Plugin) handleErrorsSection(w io.Writer) {

var totalWritten int

writeErrorToOutputSink := func(err error) {
writeErrorToOutputSink := func(err error, fieldname string) {
written, writeErr := fmt.Fprintf(w, "* %v%s", err, CheckOutputEOL)
if writeErr != nil {
panic("Failed to write LastError field content to given output sink")
msg := fmt.Sprintf("Failed to write error field %q value to given output sink", fieldname)
panic(msg)
}

totalWritten += written
Expand All @@ -79,13 +80,16 @@ func (p Plugin) handleErrorsSection(w io.Writer) {
totalWritten += written

if p.LastError != nil {
writeErrorToOutputSink(p.LastError)
p.logAction("Writing field p.LastError value to output sink")

writeErrorToOutputSink(p.LastError, "p.LastError")
}

// Process any non-nil errors in the collection.
p.logAction(fmt.Sprintf("Writing %d errors from field %q to output sink", len(p.Errors), "p.Errors"))
for _, err := range p.Errors {
if err != nil {
writeErrorToOutputSink(err)
writeErrorToOutputSink(err, "p.Errors")
}
}

Expand Down

0 comments on commit 4b18424

Please sign in to comment.