Skip to content

Commit e699dc7

Browse files
committed
chore: lint fixes part 10
1 parent 9edf045 commit e699dc7

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

circuitbreaker/circuitbreaker.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package circuitbreaker
22

33
import (
4+
"bufio"
45
"errors"
56
"fmt"
7+
"net"
68
"net/http"
79
"sync"
810
"time"
@@ -101,7 +103,8 @@ func (p *ProviderCircuitBreakers) Get(endpoint, model string) *gobreaker.Circuit
101103
}
102104

103105
// statusCapturingWriter wraps http.ResponseWriter to capture the status code.
104-
// It also implements http.Flusher to support streaming responses.
106+
// It implements http.Flusher to support streaming and http.Hijacker to
107+
// satisfy the FullResponseWriter lint rule.
105108
type statusCapturingWriter struct {
106109
http.ResponseWriter
107110
statusCode int
@@ -130,6 +133,14 @@ func (w *statusCapturingWriter) Flush() {
130133
}
131134
}
132135

136+
func (w *statusCapturingWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
137+
h, ok := w.ResponseWriter.(http.Hijacker)
138+
if !ok {
139+
return nil, nil, xerrors.New("upstream ResponseWriter does not support hijacking")
140+
}
141+
return h.Hijack()
142+
}
143+
133144
// Unwrap returns the underlying ResponseWriter for interface checks.
134145
func (w *statusCapturingWriter) Unwrap() http.ResponseWriter {
135146
return w.ResponseWriter

intercept/chatcompletions/paramswrap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (c *ChatCompletionNewParamsWrapper) lastUserPrompt() (*string, error) {
5252
// We only care if the last message was issued by a user.
5353
msg := c.Messages[len(c.Messages)-1]
5454
if msg.OfUser == nil {
55-
return nil, nil
55+
return nil, nil //nolint:nilnil // no user prompt found is not an error
5656
}
5757

5858
if msg.OfUser.Content.OfString.String() != "" {
@@ -69,5 +69,5 @@ func (c *ChatCompletionNewParamsWrapper) lastUserPrompt() (*string, error) {
6969
}
7070
}
7171

72-
return nil, nil
72+
return nil, nil //nolint:nilnil // no text content found is not an error
7373
}

intercept/messages/base_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ func (m *mockServerProxier) GetTool(id string) *mcp.Tool {
812812
}
813813

814814
func (*mockServerProxier) CallTool(context.Context, string, any) (*mcpgo.CallToolResult, error) {
815-
return nil, nil
815+
return nil, nil //nolint:nilnil // mock: no-op implementation
816816
}
817817

818818
func TestFilterBedrockBetaFlags(t *testing.T) {

intercept/messages/streaming.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,11 @@ newStream:
515515
}
516516

517517
shutdownCtx, shutdownCancel := context.WithTimeout(ctx, time.Second*30)
518-
defer shutdownCancel()
519518
// Give the events stream 30 seconds (TODO: configurable) to gracefully shutdown.
520519
if err := events.Shutdown(shutdownCtx); err != nil {
521520
logger.Warn(ctx, "event stream shutdown", slog.Error(err))
522521
}
522+
shutdownCancel()
523523

524524
// Cancel the stream context, we're now done.
525525
if interceptionErr != nil {

intercept/responses/base.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ func (i *responsesInterceptionBase) validateRequest(ctx context.Context, w http.
127127
// sendCustomErr sends custom responses.Error error to the client
128128
// it should only be called before any data is sent back to the client
129129
func (i *responsesInterceptionBase) sendCustomErr(ctx context.Context, w http.ResponseWriter, code int, err error) {
130-
respErr := responses.Error{
130+
// Same JSON shape as responses.Error but using a plain struct because
131+
// responses.Error embeds *http.Request whose GetBody func field
132+
// is not JSON-marshalable (SA1026).
133+
respErr := struct {
134+
Code string `json:"code"`
135+
Message string `json:"message"`
136+
}{
131137
Code: strconv.Itoa(code),
132138
Message: err.Error(),
133139
}

internal/testutil/mockprovider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ func (m *MockProvider) CreateInterceptor(w http.ResponseWriter, r *http.Request,
3232
if m.InterceptorFunc != nil {
3333
return m.InterceptorFunc(w, r, tracer)
3434
}
35-
return nil, nil
35+
return nil, nil //nolint:nilnil // mock: no interceptor configured is not an error
3636
}

0 commit comments

Comments
 (0)