-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.go
More file actions
45 lines (35 loc) · 745 Bytes
/
format.go
File metadata and controls
45 lines (35 loc) · 745 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
package errors
const (
_emptyJSONString = "{}"
_emptyString = ""
)
// Format formats the error as a string
func Format(err error) string {
if err == nil {
return _emptyString
}
if err, ok := err.(*errorStack); ok {
return err.formatText()
}
return err.Error()
}
// FormatJson formats the error as a JSON string
func FormatJson(err error) string {
if err == nil {
return _emptyJSONString
}
if err, ok := err.(*errorStack); ok {
return err.formatJson()
}
return err.Error()
}
// FormatColorized formats the error as a colorized string
func FormatColorized(err error) string {
if err == nil {
return _emptyString
}
if err, ok := err.(*errorStack); ok {
return err.formatColorized()
}
return err.Error()
}