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

shogo82148 / ridgenative / 29195405412

12 Jul 2026 01:59PM UTC coverage: 75.322% (+0.8%) from 74.561%
29195405412

Pull #116

github

shogo82148
Refactor error handling in lambdaErrorResponse to use errors.As for type assertion
Pull Request #116: migrate encoding/json/v2

214 of 304 new or added lines in 9 files covered. (70.39%)

702 of 932 relevant lines covered (75.32%)

4.07 hits per line

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

72.0
/error_capturing_reader_jsonv2.go
1
//go:build go1.27
2

3
package ridgenative
4

5
import (
6
        "encoding/base64"
7
        "encoding/json/v2"
8
        "errors"
9
        "io"
10
        "net/http"
11
)
12

13
// errorCapturingReader is a reader that captures the first error returned by the underlying reader.
14
type errorCapturingReader struct {
15
        reader  io.ReadCloser
16
        err     error
17
        trailer http.Header
18
}
19

20
func newErrorCapturingReader(r io.ReadCloser) *errorCapturingReader {
21
        return &errorCapturingReader{
1✔
22
                reader:  r,
1✔
23
                trailer: http.Header{},
1✔
24
        }
1✔
25
}
26

27
func (r *errorCapturingReader) Read(p []byte) (int, error) {
28
        if r.reader == nil {
1✔
NEW
29
                return 0, io.EOF
×
NEW
30
        }
×
31
        if r.err != nil {
1✔
NEW
32
                return 0, r.err
×
NEW
33
        }
×
34

35
        n, err := r.reader.Read(p)
1✔
36
        if err != nil && !errors.Is(err, io.EOF) {
1✔
37
                // capture the error
38
                lambdaErr := lambdaErrorResponse(err)
1✔
39
                body, err := json.Marshal(lambdaErr)
1✔
40
                if err != nil {
1✔
41
                        // marshaling lambdaErr always succeeds
42
                        // because lambdaErr doesn't have any functions and channels.
NEW
43
                        panic(err)
×
44
                }
45
                r.trailer.Set(trailerLambdaErrorType, lambdaErr.Type)
1✔
46
                r.trailer.Set(trailerLambdaErrorBody, base64.StdEncoding.EncodeToString(body))
1✔
47
                r.err = io.EOF
1✔
48
                return n, io.EOF
1✔
49
        }
50
        return n, err
1✔
51
}
52

53
func (r *errorCapturingReader) Close() error {
54
        if r.reader == nil {
1✔
NEW
55
                return nil
×
NEW
56
        }
×
57
        return r.reader.Close()
1✔
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc