-
Notifications
You must be signed in to change notification settings - Fork 19
/
error.go
48 lines (39 loc) · 1.14 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
package events
import (
"fmt"
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/flows"
)
func init() {
registerType(TypeError, func() flows.Event { return &ErrorEvent{} })
}
// TypeError is the type of our error events
const TypeError string = "error"
// ErrorEvent events are created when an error occurs during flow execution.
//
// {
// "type": "error",
// "created_on": "2006-01-02T15:04:05Z",
// "text": "invalid date format: '12th of October'"
// }
//
// @event error
type ErrorEvent struct {
baseEvent
Text string `json:"text" validate:"required"`
}
// NewError returns a new error event for the passed in error
func NewError(err error) *ErrorEvent {
return NewErrorf(err.Error())
}
// NewErrorf returns a new error event for the passed in format string and args
func NewErrorf(format string, a ...interface{}) *ErrorEvent {
return &ErrorEvent{
baseEvent: newBaseEvent(TypeError),
Text: fmt.Sprintf(format, a...),
}
}
// NewDependencyError returns an error event for a missing dependency
func NewDependencyError(ref assets.Reference) *ErrorEvent {
return NewErrorf("missing dependency: %s", ref.String())
}