-
Notifications
You must be signed in to change notification settings - Fork 19
/
error.go
66 lines (49 loc) · 1.59 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package types
import (
"fmt"
"github.com/nyaruka/gocommon/jsonx"
"github.com/nyaruka/goflow/envs"
)
// XError is an error
type XError struct {
baseValue
native error
}
// NewXError creates a new XError
func NewXError(err error) *XError {
return &XError{native: err}
}
// NewXErrorf creates a new XError
func NewXErrorf(format string, a ...any) *XError {
return NewXError(fmt.Errorf(format, a...))
}
// Describe returns a representation of this type for error messages
func (x *XError) Describe() string { return "error" }
// Truthy determines truthiness for this type
func (x *XError) Truthy() bool { return false }
// Render returns the canonical text representation
func (x *XError) Render() string { return x.Native().Error() }
// Format returns the pretty text representation
func (x *XError) Format(env envs.Environment) string { return "" }
// MarshalJSON converts this type to JSON
func (x *XError) MarshalJSON() ([]byte, error) { return jsonx.Marshal(nil) }
// String returns the native string representation of this type for debugging
func (x *XError) String() string { return `XError("` + x.Native().Error() + `")` }
// Native returns the native value of this type
func (x *XError) Native() error {
if x == nil {
return nil
}
return x.native
}
func (x *XError) Error() string { return x.Native().Error() }
// Equals determines equality for this type
func (x *XError) Equals(o XValue) bool {
other := o.(*XError)
return x.String() == other.String()
}
// IsXError returns whether the given value is an error value
func IsXError(x XValue) bool {
_, isError := x.(*XError)
return isError
}