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

Improved error handling #301

Merged
merged 14 commits into from
Sep 20, 2024
Merged

Improved error handling #301

merged 14 commits into from
Sep 20, 2024

Conversation

wneessen
Copy link
Owner

The error handling was refactored in accordance to #168. Errors are not nested into each other anymore. The send logic for a single message has been moved to the non-version-specific Client.go while the version-specific only handle multi-message handling and error combination. Error messages now also refer to a message ID of the message that failed (if present), for easier debugging.

This PR closes #168

wneessen and others added 14 commits July 16, 2024 13:07
The error handling process in sending messages has been refactored for better accuracy and efficiency. Instead of immediately joining errors and returning, they are now collected in a slice and joined in a deferred function to ensure all errors are captured before being returned. Furthermore, the SendError structure has been updated to include a reference to the affected message, providing better context for each error.
Extracted message sending functionality into a new helper function `sendSingleMsg`. This improves the code readability and maintainability by reducing the complexity of the main loop and encapsulating error handling per message.
Changed from range over messages to range with index to correctly update sendError field in the original messages slice. This prevents shadowing issues and ensures proper error logging for each message.
Renamed the variable 'failed' to 'hasError' to better reflect its purpose and improve code readability. This change helps in understanding that the variable indicates the presence of an error rather than a generic failure.
Consolidated the message sending logic into a single `sendSingleMsg` function to reduce duplication and improve code maintainability. This change simplifies the `Send` method in multiple Go version files by removing redundant code and calling the new helper function instead.
Renamed variable `cerr` to `err` for consistency. This improves readability and standardizes error variable naming within the method.
Introduced GetMessageID to retrieve the Message ID from the Msg
Included the affected message in the SendError struct for better error tracking and debugging. This enhancement ensures that any errors encountered during the sending process can be directly associated with the specific message that caused them.
Include the affected message ID in the error message to provide more context for debugging. This change ensures that each error log contains essential information about the specific message associated with the error.
Replaced `getTestConnection` with `getTestConnectionNoTestPort` for tests that skip port configuration, improving connection setup flexibility. Added environment variable support for setting ports in `getTestClient` to streamline port configuration in tests.
This commit introduces a new test case to verify the behavior of the IsTemp method when called on a nil SendError instance. It ensures that the method returns false as expected, improving test coverage for edge cases.
Reformat the construction of SendError objects for better readability. This improves the clarity and maintainability of the error handling code within the client.go file.
@wneessen wneessen linked an issue Sep 20, 2024 that may be closed by this pull request
Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 61.72840% with 31 lines in your changes missing coverage. Please review.

Project coverage is 85.37%. Comparing base (d3bea90) to head (d400379).
Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
client.go 52.30% 23 Missing and 8 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #301      +/-   ##
==========================================
+ Coverage   85.27%   85.37%   +0.09%     
==========================================
  Files          25       25              
  Lines        2078     2092      +14     
==========================================
+ Hits         1772     1786      +14     
  Misses        181      181              
  Partials      125      125              

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

@wneessen
Copy link
Owner Author

Codecov Report

Attention: Patch coverage is 61.72840% with 31 lines in your changes missing coverage. Please review.

Project coverage is 85.37%. Comparing base (d3bea90) to head (d400379).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
client.go 52.30% 23 Missing and 8 partials ⚠️
Additional details and impacted files

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

Will be adressed in a separate PR.

@wneessen wneessen merged commit 619318b into main Sep 20, 2024
25 of 26 checks passed
@wneessen wneessen deleted the feature/168_improve-error-handling branch September 20, 2024 09:03
@mitar
Copy link

mitar commented Sep 20, 2024

Awesome. Could SendError expose affected message ID (or even full message) through a method?

@wneessen
Copy link
Owner Author

Absolutely! I'm currently trying to implement a simple tcp test server for being able to test the senderrors better. I'll add this as a feature as well.

wneessen added a commit that referenced this pull request Sep 20, 2024
Refine Send method to correctly typecast and accumulate SendError instances. Introduce "errors" package import to utilize errors.As for precise error type checking, ensuring accurate error lists. This regression was introduced with PR #301
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error handling
2 participants