-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrf_err.go
More file actions
51 lines (39 loc) · 1018 Bytes
/
rf_err.go
File metadata and controls
51 lines (39 loc) · 1018 Bytes
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
package rf
import "strings"
// All errors generated by this package have this type.
type Err struct {
While string
Cause error
}
// Implement the `error` interface.
func (self Err) Error() string { return self.format(``) }
// Implement a hidden interface in "errors".
func (self Err) Unwrap() error { return self.Cause }
func (self Err) format(typ string) string {
var buf strings.Builder
buf.Grow(128)
buf.WriteString(`[rf] error`)
if typ != `` {
buf.WriteString(` "`)
buf.WriteString(typ)
buf.WriteString(`"`)
}
if self.While != `` {
buf.WriteString(` while `)
buf.WriteString(self.While)
}
if self.Cause != nil {
buf.WriteString(`: `)
buf.WriteString(self.Cause.Error())
}
return buf.String()
}
/*
String typedef that implements `error`. Errors of this type can be defined as
constants.
*/
type ErrStr string
// Implement `error`.
func (self ErrStr) Error() string { return string(self) }
// Implement `fmt.Stringer`.
func (self ErrStr) String() string { return string(self) }