• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

fredbi / go-cli / 6734984523

02 Nov 2023 03:48PM UTC coverage: 76.135% (-0.5%) from 76.649%
6734984523

push

github

web-flow
fixed injectables (#5)

* fixed zap logger injectable context key
* ensured xxxFromContext does not panic when nil
* added lock to guard global die function

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

19 of 19 new or added lines in 4 files covered. (100.0%)

587 of 771 relevant lines covered (76.13%)

16.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.52
/cli/fatal.go
1
package cli
2

3
import (
4
        "fmt"
5
        "log"
6
        "sync"
7
)
8

9
var (
10
        die = log.Fatalf
11
        mx  sync.Mutex
12
)
13

14
// SetDie alters the package level log.Fatalf implementation,
15
// to be used by Die(sring, ...any).
16
//
17
// If fatalFunc is set to nil, calls to Die will issue their message
18
// with panic instead of log.Fatalf.
19
//
20
// This should be used for testing only.
21
func SetDie(fatalFunc func(string, ...any)) {
2✔
22
        mx.Lock()
2✔
23
        defer mx.Unlock()
2✔
24

2✔
25
        die = fatalFunc
2✔
26
}
2✔
27

28
// Die exits the current process with some final croak.
29
// By default, Die is a wrapper around log.Fatalf.
30
//
31
// Use SetDie to alter this behavior (e.g. for mocking).
32
//
33
// SetDie(nil) will make Die(format, args...) equivalent to
34
// panic(fmt.Sprintf(format, args...)).
35
//
36
// This wraps log.Fatalf, essentially for testing purpose.
37
func Die(format string, args ...any) {
1✔
38
        if die == nil {
1✔
39
                panic(fmt.Sprintf(format, args...))
×
40
        }
41

42
        die(format, args...)
1✔
43
}
44

45
// Must panic on error
46
func Must(err error) {
×
47
        must(err)
×
48
}
×
49

50
// MustOrDie dies on error.
51
//
52
// Croaks a message like log.Fatalf(msg + ": %v", err)
53
func MustOrDie(msg string, err error) {
×
54
        if err == nil {
×
55
                return
×
56
        }
×
57

58
        die(fmt.Sprintf("%s: %%v", msg), err)
×
59
}
60

61
func must(err error) {
12✔
62
        if err == nil {
24✔
63
                return
12✔
64
        }
12✔
65

66
        panic(err)
×
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc