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

nats-io / nats-server / 19658562439

24 Nov 2025 12:55PM UTC coverage: 69.106% (-17.0%) from 86.129%
19658562439

push

github

web-flow
NRG: Don't reset WAL when failing to load last snapshot (#7580)

In most cases we can either install a new snapshot before shutting down,
or if not, we can better detect the situation on the next startup.

ref: #7556

Signed-off-by: Neil Twigg <neil@nats.io>

60221 of 87143 relevant lines covered (69.11%)

271294.87 hits per line

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

97.87
/server/jetstream_errors.go
1
package server
2

3
import (
4
        "fmt"
5
)
6

7
type errOpts struct {
8
        err error
9
}
10

11
// ErrorOption configures a NATS Error helper
12
type ErrorOption func(*errOpts)
13

14
// Unless ensures that if err is a ApiErr that err will be returned rather than the one being created via the helper
15
func Unless(err error) ErrorOption {
7,328✔
16
        return func(opts *errOpts) {
14,656✔
17
                opts.err = err
7,328✔
18
        }
7,328✔
19
}
20

21
func parseOpts(opts []ErrorOption) *errOpts {
71,786✔
22
        eopts := &errOpts{}
71,786✔
23
        for _, opt := range opts {
79,114✔
24
                opt(eopts)
7,328✔
25
        }
7,328✔
26
        return eopts
71,786✔
27
}
28

29
type ErrorIdentifier uint16
30

31
// IsNatsErr determines if an error matches ID, if multiple IDs are given if the error matches any of these the function will be true
32
func IsNatsErr(err error, ids ...ErrorIdentifier) bool {
350✔
33
        if err == nil {
617✔
34
                return false
267✔
35
        }
267✔
36

37
        ce, ok := err.(*ApiError)
83✔
38
        if !ok || ce == nil {
91✔
39
                return false
8✔
40
        }
8✔
41

42
        for _, id := range ids {
202✔
43
                ae, ok := ApiErrors[id]
127✔
44
                if !ok || ae == nil {
127✔
45
                        continue
×
46
                }
47

48
                if ce.ErrCode == ae.ErrCode {
140✔
49
                        return true
13✔
50
                }
13✔
51
        }
52

53
        return false
62✔
54
}
55

56
// ApiError is included in all responses if there was an error.
57
type ApiError struct {
58
        Code        int    `json:"code"`
59
        ErrCode     uint16 `json:"err_code,omitempty"`
60
        Description string `json:"description,omitempty"`
61
}
62

63
// ErrorsData is the source data for generated errors as found in errors.json
64
type ErrorsData struct {
65
        Constant    string `json:"constant"`
66
        Code        int    `json:"code"`
67
        ErrCode     uint16 `json:"error_code"`
68
        Description string `json:"description"`
69
        Comment     string `json:"comment"`
70
        Help        string `json:"help"`
71
        URL         string `json:"url"`
72
        Deprecates  string `json:"deprecates"`
73
}
74

75
func (e *ApiError) Error() string {
20,399✔
76
        return fmt.Sprintf("%s (%d)", e.Description, e.ErrCode)
20,399✔
77
}
20,399✔
78

79
func (e *ApiError) toReplacerArgs(replacements []any) []string {
7,420✔
80
        var (
7,420✔
81
                ra  []string
7,420✔
82
                key string
7,420✔
83
        )
7,420✔
84

7,420✔
85
        for i, replacement := range replacements {
22,264✔
86
                if i%2 == 0 {
22,266✔
87
                        key = replacement.(string)
7,422✔
88
                        continue
7,422✔
89
                }
90

91
                switch v := replacement.(type) {
7,422✔
92
                case string:
8✔
93
                        ra = append(ra, key, v)
8✔
94
                case error:
7,394✔
95
                        ra = append(ra, key, v.Error())
7,394✔
96
                default:
20✔
97
                        ra = append(ra, key, fmt.Sprintf("%v", v))
20✔
98
                }
99
        }
100

101
        return ra
7,420✔
102
}
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