github.com/haraldrudell/parl@v0.4.176/perrors/errorglue/warning.go (about)

     1  /*
     2  © 2021–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package errorglue
     7  
     8  const warningString = "warning: "
     9  
    10  // warningType is an error with lesser impact
    11  type WarningType struct {
    12  	ErrorChain
    13  }
    14  
    15  var _ error = &WarningType{}   // WarningType behaves like an error
    16  var _ Wrapper = &WarningType{} // WarningType has an error chain
    17  
    18  func NewWarning(err error) error {
    19  	return &WarningType{*newErrorChain(err)}
    20  }
    21  
    22  // Error prepends “Warning: ” to the error message
    23  func (w *WarningType) Error() (s string) {
    24  	return warningString + w.ErrorChain.Error()
    25  }