-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
45 lines (38 loc) · 1.27 KB
/
main.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
package main
import (
"errors"
"fmt"
"time"
"github.com/charmbracelet/log"
"github.com/sebastianwebber/berr"
)
var (
simpleError = berr.New("simple error")
// since berr.betterError implements the Error interface, it can
// be used as a normal error.
complexError = fmt.Errorf("complex error: %w", simpleError)
veryComplexError = fmt.Errorf("very complex error: %w", complexError)
ultraComplexError = fmt.Errorf("ultra complex error: %w", veryComplexError)
godLikeComplexError = fmt.Errorf("god like complex error: %w", ultraComplexError)
abortError = fmt.Errorf("need to abort: %w", complexError)
examples = map[string]error{
"simple error": simpleError,
"complex error": complexError,
"very complex error": veryComplexError,
"ultra complex error": ultraComplexError,
"god like complex error": godLikeComplexError,
"join error": errors.Join(simpleError, complexError),
}
)
func main() {
defer endFunc()
for k, v := range examples {
berr.Logger(v, "example", k).Info("message")
time.Sleep(1 * time.Second)
}
}
func endFunc() {
berr.Options.PrintStack = true
// you could only use the formatter if you want
log.Fatal("finishing with an error and stack trace", "details", berr.Format(abortError))
}