Commit graph

14 commits

Author SHA1 Message Date
0ea9631855
Refactor error handling in message delivery process
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.
2024-07-16 13:07:20 +02:00
077cf47973
Refactor variable names for better clarity
Changed variable names for more clarity in senderror.go. This change has converted abbreviated variable names into meaningful and self-explanatory variables. This effort improves code readability and maintainability following Go's best practices.
2024-02-27 11:32:12 +01:00
81306e4dd3
Fix null pointer exception in Is function
Updated the Is function in senderror.go to handle null values for SendError. This was done by adding a nil-check for surfaced pointer errors in the errors.As call. This prevents the function from attempting to derive values from a null pointer and consequently prevents null pointer exceptions from being thrown.
2023-11-29 17:20:09 +01:00
cf678be9dd
Handle nil pointer in IsTemp method in senderror.go
Added a nil check in the IsTemp method in senderror.go to prevent runtime errors when method is called on a nil object. The method now immediately returns false if it is invoked on a nil *SendError, ensuring the program's robustness against potential misuse. This increases the robustness and readability of the
2023-11-20 18:45:35 +01:00
3922d3f195
Switched copyright header from me to "The go-mail Authors" 2023-01-15 16:14:19 +01:00
8d86c3d8b2
Better test coverage for senderror.go 2023-01-02 21:55:37 +01:00
8463f8524a
Fix merge conflict 2023-01-02 12:16:47 +01:00
b8af7a6ffc
Merge remote-tracking branch 'origin/feature/90_provide-a-way-of-knowing-which-emails-failedsucceeded-in-sending' into feature/90_provide-a-way-of-knowing-which-emails-failedsucceeded-in-sending
# Conflicts:
#	senderror.go
2023-01-02 12:15:39 +01:00
2c7ea3e532
More changes in regard to #90
As proposed by @iwittkau the `SendError` type now has a `IsTemp()` method as well indicating to the user if the delivery error is retryable or not.

Since we want to use it in the error response from the Client functions like `Send` or `DialAndSend` we need to return the SendError type not only as part of the `*Msg` but also as return value for these methods. Hence, the changes made for #85 been overhauled to return the new error type instead. In the pre Go1.20 version of the `Send()` method we need to return an accumulated version of the SendError type, since we don't have `errors.Join()` and therefore, if more than one error occurred during the delivery we return an ambiguous error reason since we can't tell which of the captured errors is main error. For more details the user can always check the `*Msg.SendError`
2023-01-02 12:14:14 +01:00
15b3a0028a
Fix/optimize isTempError method
Not that this particular part of the code is performance critical, but I figured that the `strconv.Atoi()` is actually useless in here.

Since all we want to know is if the error code from the SMTP server is a 4xx error, we can just check the first rune of the returned error. The `Atoi` provides us with no advantage over the simple rune compare (except of taking about 3ns longer to execute)
2023-01-01 20:35:21 +01:00
f6709e90cd
Make golangci-lint happy by using errors.As instead of using type assertion on error (which can fail on wrapped errors) 2023-01-01 14:25:00 +01:00
78df991399
Proposal change for #90
Did a complete overhaul of the senderror.go.

- the list of `errors.New()` has been replaced with constant itoa error reasons as `SendErrReason`. Instead, the `Error()` method now reports the corresponding error message based on the reason.
- The `SendError` received a `Is()` method so that we can use `errors.Is()` for very specific error checking. I.e. we can check for `&SendErrors{Reason: ErrSMTPMailFrom, isTemp: true}`. This provides much more flexibility in the error checking capabilities
- A `isTemp` field has been added to the `SendError` type, indicating whether the received error is temporary and can be retried or not. Accordingly, the `*Msg` now has a `SendErrorIsTemp()` method indicating the same. The decision is based on the first 3 characters returned from the SMTP server. If the error code is within the 4xx range, the error is seen as temporary
- A test for the SendError type has been added
2023-01-01 14:20:13 +01:00
42a1fde51f
Fix missing REUSE license header in senderror.go 2022-12-31 12:47:20 +01:00
47bff15de9
Introduction of a Msg error type as proposal for #90
This PR introduces the `SendError` type which implements the error interface.

A new `senderror` field has been added to the `Msg` as well, so introduce this type to it.

I've also added different error variables that indicate the different things that can go wrong during mail delivery. These variables can be checked for, for each `Msg` using the `errors.As` method

The `Error()` method of `SendError` will return a detailed error string on why the `Msg` could not be delivered.

Additionally, `HasSendError()` and `SendError()` methods have been added to `Msg`. While `HasSendError()` simply returns a bool in case a `Msg` failed during delivery, the `SendError()` will return the full `SendError` error interface.
2022-12-31 12:40:42 +01:00