github.phpd.cn/cilium/cilium@v1.6.12/test/helpers/errors.go (about)

     1  package helpers
     2  
     3  import "fmt"
     4  
     5  // NewSSHMetaError returns a new SSHMetaError with the given string and a
     6  // callback function
     7  func NewSSHMetaError(errorString string, callback func() string) *SSHMetaError {
     8  	if callback == nil {
     9  		callback = func() string { return "Invalid callback" }
    10  	}
    11  	return &SSHMetaError{
    12  		errorString:   errorString,
    13  		errorCallBack: callback,
    14  	}
    15  }
    16  
    17  // SSHMetaError is a custom error that executes a callback function when its
    18  // Error() function is invoked
    19  type SSHMetaError struct {
    20  	errorString   string
    21  	errorCallBack func() string
    22  }
    23  
    24  func (e *SSHMetaError) String() string {
    25  	return fmt.Sprintf(
    26  		"Error: %s\nExtended info: %s\n",
    27  		e.errorString, e.errorCallBack())
    28  }
    29  
    30  func (e *SSHMetaError) Error() string {
    31  	return e.String()
    32  }