-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.go
69 lines (57 loc) · 1.81 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
69
/**********************************************************\
* *
* promise/error.go *
* *
* promise error for Go. *
* *
* LastModified: Aug 18, 2016 *
* Author: Ma Bingyao <[email protected]> *
* *
\**********************************************************/
package promise
import (
"fmt"
"runtime"
)
// IllegalArgumentError represents an error when a function/method has been
// passed an illegal or inappropriate argument.
type IllegalArgumentError string
// Error implements the IllegalArgumentError Error method.
func (e IllegalArgumentError) Error() string {
return string(e)
}
// TimeoutError represents an error when an operation times out.
type TimeoutError struct{}
// Error implements the TimeoutError Error method.
func (TimeoutError) Error() string {
return "timeout"
}
// TypeError represents an error when a value is not of the expected type.
type TypeError string
// Error implements the TypeError Error method.
func (e TypeError) Error() string {
return string(e)
}
// 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)
}