Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TT-11758] fix sonarcloud reported issues on errorlint.bug.major (Tyk…
…Technologies#6434) ### **User description** <!-- Provide a general summary of your changes in the Title above --> ## Description fix issues reported on [sonarcloud](https://sonarcloud.io/project/issues?rules=external_golangci-lint%3Aerrorlint.bug.major&issueStatuses=OPEN%2CCONFIRMED&types=BUG&id=TykTechnologies_tyk) via goalngcilint ## Related Issue https://tyktech.atlassian.net/browse/TT-11758 ## Motivation and Context <!-- Why is this change required? What problem does it solve? --> ## How This Has Been Tested <!-- Please describe in detail how you tested your changes --> <!-- Include details of your testing environment, and the tests --> <!-- you ran to see how your change affects other areas of the code, etc. --> <!-- This information is helpful for reviewers and QA. --> ## Screenshots (if appropriate) ## Types of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Refactoring or add test (improvements in base code or adds test coverage to functionality) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply --> <!-- If there are no documentation updates required, mark the item as checked. --> <!-- Raise up any additional concerns not covered by the checklist. --> - [ ] I ensured that the documentation is up to date - [ ] I explained why this PR updates go.mod in detail with reasoning why it's required - [ ] I would like a code coverage CI quality gate exception and have explained why ___ ### **PR Type** Bug fix, Enhancement ___ ### **Description** - Added `errors` package import where necessary. - Replaced direct error comparisons with `errors.Is` for better error handling. - Used `%w` for error wrapping to provide more context. - Standardized error messages to start with lowercase letters. - Improved error handling in various test files using `assert.ErrorIsf`. ___ ### **Changes walkthrough** 📝 <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><details><summary>19 files</summary><table> <tr> <td> <details> <summary><strong>bundler_test.go</strong><dd><code>Improve error handling in bundler tests</code> </dd></summary> <hr> cli/bundler/bundler_test.go <li>Added <code>errors</code> package import.<br> <li> Replaced direct error comparisons with <code>errors.Is</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-ca677a25368595e118a0500bbde9d4bad2e757eaf1cbdb2514a95a9670786028">+4/-3</a> </td> </tr> <tr> <td> <details> <summary><strong>importer.go</strong><dd><code>Standardize error messages and improve error wrapping</code> </dd></summary> <hr> cli/importer/importer.go <li>Standardized error messages to lowercase.<br> <li> Replaced direct error comparisons with <code>errors.Is</code>.<br> <li> Used <code>%w</code> for error wrapping.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-2e14c21430010c2da93c039ec6e6df36715bb097488416389dec548d1db2be46">+27/-27</a> </td> </tr> <tr> <td> <details> <summary><strong>analytics_go_plugin.go</strong><dd><code>Simplify error assignment in defer function</code> </dd></summary> <hr> gateway/analytics_go_plugin.go - Simplified error assignment in defer function. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-cb35c821b08f61dd39174ff04aa88467294fb465840fac8041908a30d1a74d84">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>batch_requests.go</strong><dd><code>Improve error wrapping and standardize messages</code> </dd></summary> <hr> gateway/batch_requests.go <li>Used <code>%w</code> for error wrapping.<br> <li> Standardized error messages to lowercase.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-2592f5fcee155ea0616be637ef7cf4479ae41a23beaadd230c26d8e3f056cd04">+3/-3</a> </td> </tr> <tr> <td> <details> <summary><strong>coprocess_events.go</strong><dd><code>Improve error wrapping in coprocess events</code> </dd></summary> <hr> gateway/coprocess_events.go - Used `%w` for error wrapping. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-2d1a0fbc732d6ac61b375377d69d89513fb641c39c578b12a71b6e384c0ff5a8">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>dashboard_register.go</strong><dd><code>Improve error wrapping in dashboard register</code> </dd></summary> <hr> gateway/dashboard_register.go - Used `%w` for error wrapping. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-f504c88b3d2fa3b56b74c252aab41a934156879ef1150d33714225749e6cc94c">+2/-2</a> </td> </tr> <tr> <td> <details> <summary><strong>grpc_streaming_client_test.go</strong><dd><code>Improve error handling in gRPC streaming client tests</code> </dd></summary> <hr> gateway/grpc_streaming_client_test.go <li>Added <code>errors</code> package import.<br> <li> Replaced direct error comparisons with <code>errors.Is</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-1268c35895b3fe58b2bcf8a9cd4c0d75d2dde60d91e18deba254c19622d301f5">+2/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>grpc_streaming_server_test.go</strong><dd><code>Improve error handling in gRPC streaming server tests</code> </dd></summary> <hr> gateway/grpc_streaming_server_test.go <li>Added <code>errors</code> package import.<br> <li> Replaced direct error comparisons with <code>errors.Is</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-61f9d7f56d9104b7efc7a5c913b8d4958f3cd33acee96eeafe31a9df4a98337a">+3/-2</a> </td> </tr> <tr> <td> <details> <summary><strong>host_checker.go</strong><dd><code>Improve error handling in host checker</code> </dd></summary> <hr> gateway/host_checker.go <li>Added <code>errors</code> package import.<br> <li> Replaced direct error comparisons with <code>errors.Is</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-a0eaa8c9fb4c1479a5b080cd3b6faf25ce1d218ca107d5b07888d4ffc97aadac">+2/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>mock_response.go</strong><dd><code>Improve error wrapping in mock response</code> </dd></summary> <hr> gateway/mock_response.go - Used `%w` for error wrapping. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-8aef512076b7695a6fa276dfc7f2b11f9e0d3b4a4d7f33b8404cbb29b47d3a9f">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>mw_external_oauth.go</strong><dd><code>Improve error wrapping in external OAuth middleware</code> </dd></summary> <hr> gateway/mw_external_oauth.go - Used `%w` for error wrapping. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-49758921227a3506a0c29936c58d02fbc8829d140acb5730de55f6621823a82c">+4/-4</a> </td> </tr> <tr> <td> <details> <summary><strong>mw_oas_validate_request.go</strong><dd><code>Improve error wrapping in OAS request validation</code> </dd></summary> <hr> gateway/mw_oas_validate_request.go - Used `%w` for error wrapping. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-f5de96d1354ffab65e076f23a58337a7799a212f6e70dea59b56576042ecd69a">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>mw_transform.go</strong><dd><code>Improve error wrapping in request transformation</code> </dd></summary> <hr> gateway/mw_transform.go - Used `%w` for error wrapping. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-d7a3cdc3dcabd415dffee6c044ea27dbe877add0ddc42471e10943125693fc12">+2/-2</a> </td> </tr> <tr> <td> <details> <summary><strong>mw_validate_json.go</strong><dd><code>Improve error wrapping in JSON validation middleware</code> </dd></summary> <hr> gateway/mw_validate_json.go - Used `%w` for error wrapping. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-0f0c6b9ac40c5e01908a5b24b1d03111c8d8b4dbc1ddc0251d17c3c1b5328ab5">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>redis_signals.go</strong><dd><code>Improve error handling in Redis signals</code> </dd></summary> <hr> gateway/redis_signals.go <li>Added <code>errors</code> package import.<br> <li> Replaced direct error comparisons with <code>errors.Is</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-18cb136722c238e19b02741a85510dfd464343f85365482f0873aa60a37718af">+2/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>reverse_proxy.go</strong><dd><code>Improve error handling and wrapping in reverse proxy</code> </dd></summary> <hr> gateway/reverse_proxy.go <li>Replaced direct error comparisons with <code>errors.Is</code>.<br> <li> Used <code>%w</code> for error wrapping.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-e6e07722257f7e41691e471185ad6d84fd56dc9e5459526ea32e9a5e8fa1a01b">+6/-6</a> </td> </tr> <tr> <td> <details> <summary><strong>reverse_proxy_test.go</strong><dd><code>Improve error handling in reverse proxy tests</code> </dd></summary> <hr> gateway/reverse_proxy_test.go - Replaced direct error comparisons with `errors.Is`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-ce040f6555143f760fba6059744bc600b6954f0966dfb0fa2832b5eabf7a3c3f">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>graphql_request.go</strong><dd><code>Improve error handling in GraphQL request</code> </dd></summary> <hr> internal/graphql/graphql_request.go <li>Added <code>errors</code> package import.<br> <li> Replaced direct error comparisons with <code>errors.Is</code>.<br> <li> Renamed variable to avoid shadowing.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-8cc52a1c92c2035fddfc3c896e8028361b656a29a37c155ad262e9351ea8d540">+5/-4</a> </td> </tr> <tr> <td> <details> <summary><strong>tcp.go</strong><dd><code>Improve error handling in TCP proxy</code> </dd></summary> <hr> tcp/tcp.go - Replaced direct error comparisons with `errors.Is`. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-4964880da1ba03845181b6d43ad9c238e7ff6c8f6a1766deb10d65ebdcc7e4ec">+2/-2</a> </td> </tr> </table></details></td></tr><tr><td><strong>Tests</strong></td><td><details><summary>3 files</summary><table> <tr> <td> <details> <summary><strong>consul_test.go</strong><dd><code>Use assert.ErrorIsf for error comparison in Consul tests</code> </dd></summary> <hr> storage/kv/consul_test.go - Added `assert.ErrorIsf` for error comparison. </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-c657354858d474f8868624bc4a8c71e22be58b304b96e78f2150fac2d6f9cbe0">+2/-3</a> </td> </tr> <tr> <td> <details> <summary><strong>redis_cluster_test.go</strong><dd><code>Improve error handling in Redis cluster tests</code> </dd></summary> <hr> storage/redis_cluster_test.go <li>Added <code>errors</code> package import.<br> <li> Replaced direct error comparisons with <code>errors.Is</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-6881545acab41fff3221454e0efb16302c696ea1217da926f80332a62ef51c71">+1/-1</a> </td> </tr> <tr> <td> <details> <summary><strong>http.go</strong><dd><code>Improve error handling in HTTP tests</code> </dd></summary> <hr> test/http.go <li>Added <code>errors</code> package import.<br> <li> Replaced direct error comparisons with <code>errors.Is</code>.<br> </details> </td> <td><a href="https://github.com/TykTechnologies/tyk/pull/6434/files#diff-a5530e34c740ce6fe2efe8dda5a356463c450696b39b97b91228f1be2491e05e">+3/-2</a> </td> </tr> </table></details></td></tr></tr></tbody></table> ___ > 💡 **PR-Agent usage**: >Comment `/help` on the PR to get a list of all available PR-Agent tools and their descriptions --------- Co-authored-by: Jeffy Mathew <jeffymathew@Jeffys-MacBook-Pro.local>
- Loading branch information