-
Notifications
You must be signed in to change notification settings - Fork 3
/
errors.go
51 lines (42 loc) · 1.21 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
44
45
46
47
48
49
50
51
// Copyright 2018 ekino. All rights reserved.
// Use of this source code is governed by a MIT style
// license that can be found in the LICENSE file.
package godim
// ErrType base type for Error Type
type ErrType uint64
const (
// ErrTypeInjection happens in injection phase failure
ErrTypeInjection ErrType = 1 << 63
// ErrTypeProfile happens in profile definition failure
ErrTypeProfile ErrType = 1 << 62
// ErrTypeRegistry happens in internal registry failure
ErrTypeRegistry ErrType = 1 << 61
// ErrTypeGodim happens in internal godim failure
ErrTypeGodim ErrType = 1 << 60
// ErrTypeEvent happens in internal event switch
ErrTypeEvent ErrType = 1 << 59
// ErrTypeAny for any other kind of errors
ErrTypeAny ErrType = 1 << 1
)
// Error main godim error struct
type Error struct {
Err error
Type ErrType
}
// Error from error interface.
func (err Error) Error() string {
return err.Err.Error()
}
// SetErrType sets the error's type.
func (err *Error) SetErrType(er ErrType) *Error {
err.Type = er
return err
}
// IsErrType check kind of error.
func (err *Error) IsErrType(er ErrType) bool {
return (err.Type & er) > 0
}
var _ error = &Error{}
func newError(err error) *Error {
return &Error{Err: err}
}