-
Notifications
You must be signed in to change notification settings - Fork 33
/
error.go
35 lines (30 loc) · 825 Bytes
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package endly
import (
"fmt"
"strings"
)
// Error represents an workflow execution error
type Error struct {
Path []string
error error
}
// Unshift appends supplied pathFragments at the beginning
func (e *Error) Unshift(pathFragments ...string) {
var pathFragment = strings.Join(pathFragments, ".")
e.Path = append([]string{pathFragment}, e.Path...)
}
// Error returns en error
func (e *Error) Error() string {
return fmt.Sprintf("%v at %v ", e.error, strings.Join(e.Path, "/"))
}
// NewError returns new workflow exception or update path
func NewError(service, action string, err error) error {
if abstractException, ok := err.(*Error); ok {
abstractException.Unshift(service, action)
return abstractException
}
return &Error{
Path: []string{fmt.Sprintf("%v.%v", service, action)},
error: err,
}
}