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

shogo82148 / cfn-mackerel-macro / 25243787820

02 May 2026 04:30AM UTC coverage: 56.566% (+0.05%) from 56.515%
25243787820

Pull #571

github

shogo82148
go mod tidy
Pull Request #571: bump Go 1.26.2

78 of 124 new or added lines in 23 files covered. (62.9%)

2 existing lines in 1 file now uncovered.

2201 of 3891 relevant lines covered (56.57%)

4.48 hits per line

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

35.36
/dproxy/error.go
1
package dproxy
2

3
import (
4
        "errors"
5
        "fmt"
6
        "strconv"
7
)
8

9
// ErrorCode is type of errors
10
type ErrorCode int
11

12
const (
13
        // ErrorCodeType means expected type is not matched with actual.
14
        ErrorCodeType ErrorCode = iota + 1
15

16
        // ErrorCodeNotFound means key or index doesn't exist.
17
        ErrorCodeNotFound
18

19
        // ErrorCodeMapNorArray means target is not a map nor an array (for JSON Pointer)
20
        ErrorCodeMapNorArray
21

22
        // ErrorCodeConvertFailure means value conversion is failed.
23
        ErrorCodeConvertFailure
24

25
        // ErrorCodeInvalidIndex means token is invalid as index (for JSON Pointer)
26
        ErrorCodeInvalidIndex
27

28
        // ErrorCodeInvalidQuery means query is invalid as JSON Pointer.
29
        ErrorCodeInvalidQuery
30
)
31

32
func (et ErrorCode) String() string {
×
33
        switch et {
×
34
        case ErrorCodeType:
×
35
                return "ErrorCodeType"
×
36
        case ErrorCodeNotFound:
×
37
                return "ErrorCodeNotFound"
×
38
        case ErrorCodeMapNorArray:
×
39
                return "ErrorCodeMapNorArray"
×
40
        case ErrorCodeConvertFailure:
×
41
                return "ErrorCodeConvertFailure"
×
42
        case ErrorCodeInvalidIndex:
×
43
                return "ErrorCodeInvalidIndex"
×
44
        case ErrorCodeInvalidQuery:
×
45
                return "ErrorCodeInvalidQuery"
×
46
        default:
×
47
                return "Unknown"
×
48
        }
49
}
50

51
// Error get detail information of the error.
52
type Error interface {
53
        // ErrorCode returns type of error.
54
        ErrorCode() ErrorCode
55

56
        // FullAddress returns query string where cause first error.
57
        FullAddress() string
58
}
59

60
type errorProxy struct {
61
        errorCode ErrorCode
62
        parent    frame
63
        label     string
64

65
        expected Type
66
        actual   Type
67
        infoStr  string
68
}
69

70
// errorProxy implements error, Proxy and ProxySet.
71
var (
72
        _ error    = (*errorProxy)(nil)
73
        _ Proxy    = (*errorProxy)(nil)
74
        _ ProxySet = (*errorProxy)(nil)
75
)
76

77
func (p *errorProxy) Nil() bool {
×
78
        return false
×
79
}
×
80

NEW
81
func (p *errorProxy) Value() (any, error) {
×
82
        return nil, p
×
83
}
×
84

85
func (p *errorProxy) Bool() (bool, error) {
1✔
86
        return false, p
1✔
87
}
1✔
88

89
func (p *errorProxy) OptionalBool() (*bool, error) {
1✔
90
        if p.errorCode == ErrorCodeNotFound {
2✔
91
                return nil, nil
1✔
92
        }
1✔
93
        return nil, p
×
94
}
95

96
func (p *errorProxy) Int64() (int64, error) {
×
97
        return 0, p
×
98
}
×
99

100
func (p *errorProxy) OptionalInt64() (*int64, error) {
1✔
101
        if p.errorCode == ErrorCodeNotFound {
2✔
102
                return nil, nil
1✔
103
        }
1✔
104
        return nil, p
×
105
}
106

107
func (p *errorProxy) Uint64() (uint64, error) {
×
108
        return 0, p
×
109
}
×
110
func (p *errorProxy) OptionalUint64() (*uint64, error) {
1✔
111
        if p.errorCode == ErrorCodeNotFound {
2✔
112
                return nil, nil
1✔
113
        }
1✔
114
        return nil, p
×
115
}
116

117
func (p *errorProxy) Float64() (float64, error) {
×
118
        return 0, p
×
119
}
×
120

121
func (p *errorProxy) OptionalFloat64() (*float64, error) {
1✔
122
        if p.errorCode == ErrorCodeNotFound {
2✔
123
                return nil, nil
1✔
124
        }
1✔
125
        return nil, p
×
126
}
127

128
func (p *errorProxy) String() (string, error) {
1✔
129
        return "", p
1✔
130
}
1✔
131

132
func (p *errorProxy) OptionalString() (*string, error) {
1✔
133
        if p.errorCode == ErrorCodeNotFound {
2✔
134
                return nil, nil
1✔
135
        }
1✔
136
        return nil, p
×
137
}
138

NEW
139
func (p *errorProxy) Array() ([]any, error) {
×
140
        return nil, p
×
141
}
×
142

NEW
143
func (p *errorProxy) Map() (map[string]any, error) {
×
144
        return nil, p
×
145
}
×
146

147
func (p *errorProxy) A(n int) Proxy {
×
148
        return p
×
149
}
×
150

151
func (p *errorProxy) M(k string) Proxy {
×
152
        return p
×
153
}
×
154

155
func (p *errorProxy) P(q string) Proxy {
×
156
        return p
×
157
}
×
158

159
func (p *errorProxy) Empty() bool {
×
160
        return true
×
161
}
×
162

163
func (p *errorProxy) Len() int {
×
164
        return 0
×
165
}
×
166

167
func (p *errorProxy) BoolArray() ([]bool, error) {
×
168
        return nil, p
×
169
}
×
170

171
func (p *errorProxy) Int64Array() ([]int64, error) {
×
172
        return nil, p
×
173
}
×
174

175
func (p *errorProxy) Float64Array() ([]float64, error) {
×
176
        return nil, p
×
177
}
×
178

179
func (p *errorProxy) StringArray() ([]string, error) {
×
180
        return nil, p
×
181
}
×
182

NEW
183
func (p *errorProxy) ArrayArray() ([][]any, error) {
×
184
        return nil, p
×
185
}
×
186

NEW
187
func (p *errorProxy) MapArray() ([]map[string]any, error) {
×
188
        return nil, p
×
189
}
×
190

191
func (p *errorProxy) ProxyArray() ([]Proxy, error) {
×
192
        return nil, p
×
193
}
×
194

195
func (p *errorProxy) ProxySet() ProxySet {
×
196
        return p
×
197
}
×
198

199
func (p *errorProxy) Q(k string) ProxySet {
×
200
        return p
×
201
}
×
202

203
func (p *errorProxy) Qc(k string) ProxySet {
×
204
        return p
×
205
}
×
206

207
func (p *errorProxy) findJPT(t string) Proxy {
×
208
        return p
×
209
}
×
210

211
func (p *errorProxy) parentFrame() frame {
6✔
212
        return p.parent
6✔
213
}
6✔
214

215
func (p *errorProxy) frameLabel() string {
9✔
216
        return p.label
9✔
217
}
9✔
218

219
func (p *errorProxy) Error() string {
2✔
220
        switch p.errorCode {
2✔
221
        case ErrorCodeType:
×
222
                return fmt.Sprintf("not matched types: expected=%s actual=%s: %s",
×
223
                        p.expected.String(), p.actual.String(), p.FullAddress())
×
224
        case ErrorCodeNotFound:
2✔
225
                return fmt.Sprintf("not found: %s", p.FullAddress())
2✔
226
        case ErrorCodeMapNorArray:
×
227
                // FIXME: better error message.
×
228
                return fmt.Sprintf("not map nor array: actual=%s: %s",
×
229
                        p.actual.String(), p.FullAddress())
×
230
        case ErrorCodeConvertFailure:
×
231
                return fmt.Sprintf("convert error: %s: %s", p.infoStr, p.FullAddress())
×
232
        case ErrorCodeInvalidIndex:
×
233
                // FIXME: better error message.
×
234
                return fmt.Sprintf("invalid index: %s: %s", p.infoStr, p.FullAddress())
×
235
        case ErrorCodeInvalidQuery:
×
236
                // FIXME: better error message.
×
237
                return fmt.Sprintf("invalid query: %s: %s", p.infoStr, p.FullAddress())
×
238
        default:
×
239
                return fmt.Sprintf("unexpected: %s", p.FullAddress())
×
240
        }
241
}
242

243
func (p *errorProxy) ErrorCode() ErrorCode {
20✔
244
        return p.errorCode
20✔
245
}
20✔
246

247
func (p *errorProxy) FullAddress() string {
3✔
248
        return fullAddress(p)
3✔
249
}
3✔
250

251
func typeError(p frame, expected Type, actual any) *errorProxy {
4✔
252
        return &errorProxy{
4✔
253
                errorCode: ErrorCodeType,
4✔
254
                parent:    p,
4✔
255
                expected:  expected,
4✔
256
                actual:    detectType(actual),
4✔
257
        }
4✔
258
}
4✔
259

260
func elementTypeError(p frame, index int, expected Type, actual any) *errorProxy {
1✔
261
        q := &simpleFrame{
1✔
262
                parent: p,
1✔
263
                label:  "[" + strconv.Itoa(index) + "]",
1✔
264
        }
1✔
265
        return typeError(q, expected, actual)
1✔
266
}
1✔
267

268
func notfoundError(p frame, address string) *errorProxy {
7✔
269
        return &errorProxy{
7✔
270
                errorCode: ErrorCodeNotFound,
7✔
271
                parent:    p,
7✔
272
                label:     address,
7✔
273
        }
7✔
274
}
7✔
275

276
// IsError checks whether p is an error and its error code is code.
277
func IsError(p Proxy, code ErrorCode) bool {
×
278
        err, ok := p.(Error)
×
279
        return ok && err.ErrorCode() == code
×
280
}
×
281

282
// IsErrorCode checks whether the error code is code.
283
func IsErrorCode(err error, code ErrorCode) bool {
×
284
        var myErr Error
×
285
        if errors.As(err, &myErr) {
×
286
                return myErr.ErrorCode() == code
×
287
        }
×
288
        return false
×
289
}
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