Skip to content

Commit

Permalink
Fix middleware writer: (#343)
Browse files Browse the repository at this point in the history
## Description


Func now only returns an error when the error is not nil.

## Why is this needed
logs were showing an error when there wasnt one.

```json
{"level":"error","ts":1695434959.912211,"caller":"script/ipxe.go:152","msg":"unable to write boot script","script":"auto.ipxe","error":"writing response: %!w(<nil>)","stacktrace":"github.com/tinkerbell/smee/ipxe/script.(*Handler).serveBootScript\n\t/home/tink/repos/tinkerbell/boots/ipxe/script/ipxe.go:152\ngithub.com/tinkerbell/smee/ipxe/script.(*Handler).HandlerFunc.func1\n\t/home/tink/repos/tinkerbell/boots/ipxe/script/ipxe.go:108\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2122\ngo.opentelemetry.io/contrib/instrumentation/net/http/otelhttp.WithRouteTag.func1\n\t/root/go/pkg/mod/go.opentelemetry.io/contrib/instrumentation/net/http/[email protected]/handler.go:262\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2122\nnet/http.(*ServeMux).ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2500\ngo.opentelemetry.io/contrib/instrumentation/net/http/otelhttp.(*Handler).ServeHTTP\n\t/root/go/pkg/mod/go.opentelemetry.io/contrib/instrumentation/net/http/[email protected]/handler.go:212\ngithub.com/tinkerbell/smee/ipxe/http.(*loggingMiddleware).ServeHTTP\n\t/home/tink/repos/tinkerbell/boots/ipxe/http/middleware.go:35\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2936\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:1995"}
```


Fixes: #

## How Has This Been Tested?





## How are existing users impacted? What migration steps/scripts do we need?





## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
  • Loading branch information
mergify[bot] authored Sep 25, 2023
2 parents e2bed8d + 0a68eef commit e758659
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ipxe/http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ func (w *responseWriter) Write(b []byte) (int, error) {
w.statusCode = 200
}
n, err := w.ResponseWriter.Write(b)
if err != nil {
return 0, fmt.Errorf("failed writing response: %w", err)
}

return n, fmt.Errorf("writing response: %w", err)
return n, nil
}

func (w *responseWriter) WriteHeader(code int) {
Expand Down

0 comments on commit e758659

Please sign in to comment.