-
Notifications
You must be signed in to change notification settings - Fork 204
/
error.go
68 lines (57 loc) · 2.2 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
67
68
/**********************************************************\
| |
| hprose |
| |
| Official WebSite: http://www.hprose.com/ |
| http://www.hprose.org/ |
| |
\**********************************************************/
/**********************************************************\
* *
* rpc/error.go *
* *
* rpc error for Go. *
* *
* LastModified: Nov 1, 2016 *
* Author: Ma Bingyao <andot@hprose.com> *
* *
\**********************************************************/
package rpc
import (
"errors"
"fmt"
"runtime"
)
// ErrTimeout represents a timeout error
var ErrTimeout = errors.New("timeout")
// ErrServerIsAlreadyStarted represents a error
var ErrServerIsAlreadyStarted = errors.New("The server is already started")
// ErrServerIsNotStarted represents a error
var ErrServerIsNotStarted = errors.New("The server is not started")
// ErrClientIsAlreadyClosed represents a error
var ErrClientIsAlreadyClosed = errors.New("The Client is already closed")
var errURIListEmpty = errors.New("uriList must contain at least one uri")
var errNotSupportMultpleProtocol = errors.New("Not support multiple protocol.")
// PanicError represents a panic error
type PanicError struct {
Panic interface{}
Stack []byte
}
func stack() []byte {
buf := make([]byte, 1024)
for {
n := runtime.Stack(buf, false)
if n < len(buf) {
return buf[:n]
}
buf = make([]byte, 2*len(buf))
}
}
// NewPanicError return a panic error
func NewPanicError(v interface{}) *PanicError {
return &PanicError{v, stack()}
}
// Error implements the PanicError Error method.
func (pe *PanicError) Error() string {
return fmt.Sprintf("%v", pe.Panic)
}