feat: initial commit
This commit is contained in:
50
internal/core/workflow/error.go
Normal file
50
internal/core/workflow/error.go
Normal file
@ -0,0 +1,50 @@
|
||||
package workflow
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CompensationError struct {
|
||||
executionErr error
|
||||
compensationErrs []error
|
||||
}
|
||||
|
||||
func (e *CompensationError) ExecutionError() error {
|
||||
return e.executionErr
|
||||
}
|
||||
|
||||
func (e *CompensationError) CompensationErrors() []error {
|
||||
return e.compensationErrs
|
||||
}
|
||||
|
||||
func (e *CompensationError) Error() string {
|
||||
var sb strings.Builder
|
||||
|
||||
sb.WriteString("compensation error: ")
|
||||
sb.WriteString("execution error '")
|
||||
sb.WriteString(e.ExecutionError().Error())
|
||||
sb.WriteString("' resulted in following compensation errors: ")
|
||||
|
||||
for idx, err := range e.CompensationErrors() {
|
||||
if idx > 0 {
|
||||
sb.WriteString(", ")
|
||||
}
|
||||
|
||||
sb.WriteString("[")
|
||||
sb.WriteString(strconv.FormatInt(int64(idx), 10))
|
||||
sb.WriteString("] ")
|
||||
sb.WriteString(err.Error())
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func NewCompensationError(executionErr error, compensationErrs ...error) *CompensationError {
|
||||
return &CompensationError{
|
||||
executionErr: executionErr,
|
||||
compensationErrs: compensationErrs,
|
||||
}
|
||||
}
|
||||
|
||||
var _ error = &CompensationError{}
|
Reference in New Issue
Block a user