• 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

71.88
/error_capturing_reader.go
1
//go:build !go1.27
2

3
package ridgenative
4

5
import (
6
        "encoding/base64"
7
        "encoding/json"
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 {
5✔
21
        return &errorCapturingReader{
5✔
22
                reader:  r,
5✔
23
                trailer: http.Header{},
5✔
24
        }
5✔
25
}
5✔
26

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

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

53
func (r *errorCapturingReader) Close() error {
5✔
54
        if r.reader == nil {
5✔
NEW
55
                return nil
×
NEW
56
        }
×
57
        return r.reader.Close()
5✔
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