github.com/haraldrudell/parl@v0.4.176/add-error.go (about)

     1  /*
     2  © 2021–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package parl
     7  
     8  // DeferredErrorSink is a deferrable function that provides
     9  // an error to ErrorSink if
    10  // errp is non-nil pointer to non-nil error
    11  func DeferredErrorSink(errorSink ErrorSink, errp *error) {
    12  	var err error
    13  	if errp == nil {
    14  		return
    15  	} else if err = *errp; err == nil {
    16  		return
    17  	}
    18  	errorSink.AddError(err)
    19  }
    20  
    21  // AddError is a function to submit non-fatal errors
    22  //
    23  // Deprecated: should use [github.com/haraldrudell/parl.ErrorSink]
    24  // possibly the error container [github.com/haraldrudell/parl.ErrSlice]
    25  type AddError func(err error)
    26  
    27  // ErrorSink provides send of non-fatal errors
    28  // one at a time
    29  type ErrorSink interface {
    30  	// AddError is a function to submit non-fatal errors
    31  	AddError(err error)
    32  }
    33  
    34  // ErrorSource provides receive of errors one at a time
    35  type ErrorSource interface {
    36  	// WaitCh waits for the next error, possibly indefinitely
    37  	//	- a received channel closes on errors available
    38  	//	- the next invocation may return a different channel object
    39  	WaitCh() (ch AwaitableCh)
    40  	// Error returns the next error value
    41  	//	- hasValue true: err is valid
    42  	//	- hasValue false: the error source is empty
    43  	Error() (err error, hasValue bool)
    44  }
    45  
    46  // Errs provides receiving errors,
    47  // one at a time or multiple
    48  type Errs interface {
    49  	// ErrorSource provides receive of errors one at a time using
    50  	// WaitCh Error
    51  	ErrorSource
    52  	// Errors returns a slice of errors
    53  	ErrorsSource
    54  }
    55  
    56  // ErrorsSource provides receiving multiple
    57  // errors at once
    58  type ErrorsSource interface {
    59  	// Errors returns a slice of errors or nil
    60  	Errors() (errs []error)
    61  }
    62  
    63  // absent [parl.AddError] argument
    64  //
    65  // Deprecated: should use [github.com/haraldrudell/parl.ErrorSink]
    66  // possibly the error container [github.com/haraldrudell/parl.ErrSlice]
    67  var NoAddErr AddError