Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return errors instead of printing to logs #897

Merged
merged 3 commits into from
Apr 2, 2024

Conversation

apoorvajagtap
Copy link
Member

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Go Version Update
  • Dependency Update

Description

With #840 debug messages were printed to stderr, as this wasn't very application friendly. With this, the noise in the logs will be reduced, without impacting error handling.

Related Tickets & Documents

Added/updated tests?

  • Yes
  • No, and this is why: current tests does not cover the scenario of stderr logs, so no impact on tests with the changes.
  • I need help with writing tests

Run verifications and test

  • make verify is passing
  • make test is passing

Copy link

codecov bot commented Feb 14, 2024

Codecov Report

Attention: Patch coverage is 36.36364% with 14 lines in your changes are missing coverage. Please review.

Project coverage is 73.26%. Comparing base (e5f1a0a) to head (c8a6785).

❗ Current head c8a6785 differs from pull request most recent head cc16497. Consider uploading reports for the commit cc16497 to get more accurate results

Files Patch % Lines
server.go 0.00% 7 Missing ⚠️
proxy.go 0.00% 5 Missing ⚠️
client.go 83.33% 1 Missing ⚠️
conn.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #897      +/-   ##
==========================================
+ Coverage   71.60%   73.26%   +1.66%     
==========================================
  Files          11       11              
  Lines        1585     1575      -10     
==========================================
+ Hits         1135     1154      +19     
+ Misses        345      320      -25     
+ Partials      105      101       -4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With one exception, the logged errors are the result of calling a network connection Close() method on an error path. It's reasonable to ignore these close errors for two reasons:

  • The functions are returning a more important error.
  • There's nothing that the application can do with the information in the close error.

I would remove the calls to log.Printf by undoing the changes in 666c197.

If you are going to return the close error with errors.Join, then the secondary close error should come last in the list of errors. This does do things: the primary comes first in the error string; search on the error tree visits the primary error first.

The one exception is the error returned from bw.Flush(). That call should never return an error. It is correct to add the call to panic.

proxy.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
proxy.go Outdated Show resolved Hide resolved
@AlexVulaj AlexVulaj mentioned this pull request Mar 6, 2024
1 task
@apoorvajagtap apoorvajagtap requested a review from a user March 11, 2024 07:09
@AlexVulaj
Copy link
Member

This looks good to me. @greenmarmot as you've been extremely helpful with these changes, do you see any further issues with this PR as it is? If not, I'd like to go ahead and merge it.

@AlexVulaj AlexVulaj merged commit 09a6bab into gorilla:main Apr 2, 2024
7 of 10 checks passed
algitbot pushed a commit to alpinelinux/build-server-status that referenced this pull request Sep 15, 2024
This MR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/gorilla/websocket](https://github.com/gorilla/websocket) | require | patch | `v1.5.1` -> `v1.5.3` |

---

### Release Notes

<details>
<summary>gorilla/websocket (github.com/gorilla/websocket)</summary>

### [`v1.5.3`](https://github.com/gorilla/websocket/releases/tag/v1.5.3)

[Compare Source](gorilla/websocket@v1.5.2...v1.5.3)

#### Important change

This reverts the websockets package back to gorilla/websocket@931041c

#### What's Changed

-   Fixes subprotocol selection (aling with rfc6455) by [@&#8203;KSDaemon](https://github.com/KSDaemon) in gorilla/websocket#823
-   Update README.md, replace master to main by [@&#8203;mstmdev](https://github.com/mstmdev) in gorilla/websocket#862
-   Use status code constant by [@&#8203;mstmdev](https://github.com/mstmdev) in gorilla/websocket#864
-   conn.go: default close handler should not return ErrCloseSent. by [@&#8203;pnx](https://github.com/pnx) in gorilla/websocket#865
-   fix: replace ioutil.readfile with os.readfile by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#868
-   fix: add comment for the readBufferSize and writeBufferSize by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#869
-   Remove noisy printf in NextReader() and beginMessage() by [@&#8203;bcreane](https://github.com/bcreane) in gorilla/websocket#878
-   docs(echoreadall): fix function echoReadAll comment by [@&#8203;XdpCs](https://github.com/XdpCs) in gorilla/websocket#881
-   make tests parallel by [@&#8203;ninedraft](https://github.com/ninedraft) in gorilla/websocket#872
-   Upgrader.Upgrade: use http.ResposnseController by [@&#8203;ninedraft](https://github.com/ninedraft) in gorilla/websocket#871
-   Do not handle network error in `SetCloseHandler()` by [@&#8203;nak3](https://github.com/nak3) in gorilla/websocket#863
-   perf: reduce timer in write_control by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#879
-   fix: lint example code by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#890
-   feat: format message type by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#889
-   Remove hideTempErr to allow downstream users to check for errors like net.ErrClosed by [@&#8203;UnAfraid](https://github.com/UnAfraid) in gorilla/websocket#894
-   Do not timeout when WriteControl deadline is zero in gorilla/websocket#898
-   Excludes errchecks linter by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#904
-   Return errors instead of printing to logs by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#897
-   Revert " Update go version & add verification/testing tools ([#&#8203;840](gorilla/websocket#840))" by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#908
-   Fixes broken random value generation by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#926
-   Reverts back to v1.5.0 by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#929

#### New Contributors

-   [@&#8203;KSDaemon](https://github.com/KSDaemon) made their first contribution in gorilla/websocket#823
-   [@&#8203;mstmdev](https://github.com/mstmdev) made their first contribution in gorilla/websocket#862
-   [@&#8203;pnx](https://github.com/pnx) made their first contribution in gorilla/websocket#865
-   [@&#8203;rfyiamcool](https://github.com/rfyiamcool) made their first contribution in gorilla/websocket#868
-   [@&#8203;bcreane](https://github.com/bcreane) made their first contribution in gorilla/websocket#878
-   [@&#8203;XdpCs](https://github.com/XdpCs) made their first contribution in gorilla/websocket#881
-   [@&#8203;ninedraft](https://github.com/ninedraft) made their first contribution in gorilla/websocket#872
-   [@&#8203;nak3](https://github.com/nak3) made their first contribution in gorilla/websocket#863
-   [@&#8203;UnAfraid](https://github.com/UnAfraid) made their first contribution in gorilla/websocket#894
-   [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) made their first contribution in gorilla/websocket#904

**Full Changelog**: gorilla/websocket@v1.5.1...v1.5.3

### [`v1.5.2`](https://github.com/gorilla/websocket/releases/tag/v1.5.2)

[Compare Source](gorilla/websocket@v1.5.1...v1.5.2)

#### What's Changed

-   Fixes subprotocol selection (aling with rfc6455) by [@&#8203;KSDaemon](https://github.com/KSDaemon) in gorilla/websocket#823
-   Update README.md, replace master to main by [@&#8203;mstmdev](https://github.com/mstmdev) in gorilla/websocket#862
-   Use status code constant by [@&#8203;mstmdev](https://github.com/mstmdev) in gorilla/websocket#864
-   conn.go: default close handler should not return ErrCloseSent. by [@&#8203;pnx](https://github.com/pnx) in gorilla/websocket#865
-   fix: replace ioutil.readfile with os.readfile by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#868
-   fix: add comment for the readBufferSize and writeBufferSize by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#869
-   Remove noisy printf in NextReader() and beginMessage() by [@&#8203;bcreane](https://github.com/bcreane) in gorilla/websocket#878
-   docs(echoreadall): fix function echoReadAll comment by [@&#8203;XdpCs](https://github.com/XdpCs) in gorilla/websocket#881
-   make tests parallel by [@&#8203;ninedraft](https://github.com/ninedraft) in gorilla/websocket#872
-   Upgrader.Upgrade: use http.ResposnseController by [@&#8203;ninedraft](https://github.com/ninedraft) in gorilla/websocket#871
-   Do not handle network error in `SetCloseHandler()` by [@&#8203;nak3](https://github.com/nak3) in gorilla/websocket#863
-   perf: reduce timer in write_control by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#879
-   fix: lint example code by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#890
-   feat: format message type by [@&#8203;rfyiamcool](https://github.com/rfyiamcool) in gorilla/websocket#889
-   Remove hideTempErr to allow downstream users to check for errors like net.ErrClosed by [@&#8203;UnAfraid](https://github.com/UnAfraid) in gorilla/websocket#894
-   Do not timeout when WriteControl deadline is zero in gorilla/websocket#898
-   Excludes errchecks linter by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#904
-   Return errors instead of printing to logs by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#897
-   Revert " Update go version & add verification/testing tools ([#&#8203;840](gorilla/websocket#840))" by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#908
-   Fixes broken random value generation by [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) in gorilla/websocket#926

#### New Contributors

-   [@&#8203;KSDaemon](https://github.com/KSDaemon) made their first contribution in gorilla/websocket#823
-   [@&#8203;mstmdev](https://github.com/mstmdev) made their first contribution in gorilla/websocket#862
-   [@&#8203;pnx](https://github.com/pnx) made their first contribution in gorilla/websocket#865
-   [@&#8203;rfyiamcool](https://github.com/rfyiamcool) made their first contribution in gorilla/websocket#868
-   [@&#8203;bcreane](https://github.com/bcreane) made their first contribution in gorilla/websocket#878
-   [@&#8203;XdpCs](https://github.com/XdpCs) made their first contribution in gorilla/websocket#881
-   [@&#8203;ninedraft](https://github.com/ninedraft) made their first contribution in gorilla/websocket#872
-   [@&#8203;nak3](https://github.com/nak3) made their first contribution in gorilla/websocket#863
-   [@&#8203;UnAfraid](https://github.com/UnAfraid) made their first contribution in gorilla/websocket#894
-   [@&#8203;apoorvajagtap](https://github.com/apoorvajagtap) made their first contribution in gorilla/websocket#904

**Full Changelog**: gorilla/websocket@v1.5.1...v1.5.2

</details>

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

&nbsp;
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yODYuMSIsInVwZGF0ZWRJblZlciI6IjM3LjQxOS4xIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->

See merge request alpine/infra/build-server-status!14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] 1.5.1 uses log.Printf
2 participants