/
errors.go
43 lines (35 loc) · 1.19 KB
/
errors.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
package fluence
import "fmt"
type errCode uint32
const (
// non specific.
wrongRelayAddress errCode = 1000
connectionFailed errCode = 1001
sendFailed errCode = 1002
executeFailed errCode = 1003
metricsSubmissionFailed errCode = 1004
)
var (
WrongRelayAddress = NewXk6Error(wrongRelayAddress, "Wrong multi-address format", nil)
ConnectionFailed = NewXk6Error(connectionFailed, "Failed to connect to the remote peer", nil)
SendFailed = NewXk6Error(sendFailed, "Could not send particle", nil)
ExecuteFailed = NewXk6Error(executeFailed, "Could not execute particle", nil)
MetricsSubmissionFailed = NewXk6Error(metricsSubmissionFailed, "Could not submit metrics", nil)
)
type Xk6Error struct {
Code errCode
Message string
OriginalError error
}
func NewXk6Error(code errCode, msg string, originalErr error) *Xk6Error {
return &Xk6Error{Code: code, Message: msg, OriginalError: originalErr}
}
func (e Xk6Error) Error() string {
if e.OriginalError == nil {
return e.Message
}
return fmt.Sprintf(e.Message+", OriginalError: %w", e.OriginalError)
}
func (e Xk6Error) Unwrap() error {
return e.OriginalError
}