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

Expose error code in SendError #368

Merged
merged 14 commits into from
Nov 14, 2024

Conversation

wneessen
Copy link
Owner

@wneessen wneessen commented Nov 14, 2024

This PR introduces two new methods to the SendError error interface. ErrorCode() will return the error code from the SMTP server response (if available). EnhancedStatusCode() will return the enhanced status code of the error returned by the server (as described in RFC 2034). This information is only available if the server supports the "ENHANCEDSTATUSCODE" extension.

This PR closes #365

wneessen and others added 11 commits November 13, 2024 16:11
Enhance error handling by adding error code and enhanced status code to the SendError struct. This allows for better troubleshooting and debugging by providing more detailed SMTP server responses.
Updated the TestServerPortBase from 12025 to 30025 to avoid port conflicts with other services running on the common 12025 port. This adjustment aims to ensure that the tests run reliably in diverse environments.
Implemented ErrorCode method to retrieve the error code from the server response in SendError. This method distinguishes between server-generated errors and client-generated errors, returning 0 for errors generated by the client.
Implemented new unit tests for SendError to validate the enhanced status code and error codes in various scenarios, including nil SendError cases, errors with no enhanced status code, and errors with both permanent and temporary error codes. This ensures the correctness of the error handling behavior across different conditions.
Introduce a suite of unit tests for the getErrorCode function to validate its behavior with various error types, including go-mail errors, permanent and temporary errors, wrapper errors, non-4xx/5xx errors, and non-3-digit codes.
Renamed `getErrorCode` to `errorCode` and `getEnhancedStatusCode` to `enhancedStatusCode` for consistency. Updated all references in `client.go` and `senderror.go` accordingly, improving readability and maintaining uniformity across the codebase.
Renamed `getErrorCode` function to `errorCode` for consistency. Added new tests for the `enhancedStatusCode` function to validate its behavior with various error scenarios.
Added a check for the ENHANCEDSTATUSCODES extension and included error code and enhanced status code information in SendError. This helps in providing more detailed error reporting and troubleshooting.
Previously, only the isTemp flag was considered when aggregating errors. Now, the error code and enhanced status code from the last error are also included. This ensures more comprehensive error reporting and handling.
Added support for Enhanced Status Codes (ESC) when checking the SMTP client's extensions. The SendError struct now includes the error code and enhanced status code for improved diagnostics.
Structured the initialization of SendError on connection errors to improve code readability and maintainability. This change affects the error handling in both client_120.go and client_119.go by spreading the error details across multiple lines.
@wneessen wneessen linked an issue Nov 14, 2024 that may be closed by this pull request
Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 92.53731% with 5 lines in your changes missing coverage. Please review.

Project coverage is 96.50%. Comparing base (37ac2de) to head (2bde340).
Report is 19 commits behind head on main.

Files with missing lines Patch % Lines
senderror.go 92.85% 2 Missing and 1 partial ⚠️
client.go 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #368      +/-   ##
==========================================
- Coverage   96.57%   96.50%   -0.07%     
==========================================
  Files          27       27              
  Lines        2946     3005      +59     
==========================================
+ Hits         2845     2900      +55     
- Misses         70       73       +3     
- Partials       31       32       +1     

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

Moved TestServerPortBase initialization to use an environment variable `TEST_BASEPORT` if provided. This adjustment helps in specifying custom base ports for running tests, ensuring better flexibility in different testing environments.
In the CI configuration file, the TEST_BASEPORT environment variable was added to various job scopes. This ensures consistency and allows the test base port to be set properly across different OS versions and Go versions.
Changed the SMTP test server base port and updated the corresponding environment variable name to `TEST_BASEPORT_SMTP`. This ensures consistency across the test setup and CI workflow configuration.
@wneessen wneessen merged commit da6bf26 into main Nov 14, 2024
28 of 29 checks passed
@wneessen wneessen deleted the feature/365_expose-error-code-in-senderror branch November 14, 2024 09:50
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.

Expose error code in SendError
1 participant