Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit 770b425

Browse files
beeceejivy
authored andcommitted
Add SendError struct implementing the error interface
Fixes #12 [Ivy: - squash commits and revise commit message - tweak SendError to preserve both zero-index and original error message - improve documentation of SendError struct - add changelog entry]
1 parent 7151d98 commit 770b425

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [2.3.0] - *Unreleased*
6+
7+
### Added
8+
9+
- #12: Adds `SendError` to provide additional info about the cause and index of
10+
a failed attempt to transmit a batch of messages.
11+
512
## [2.2.0] - 2018-03-01
613

714
### Added

errors.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package mail
2+
3+
import "fmt"
4+
5+
// A SendError represents the failure to transmit a Message, detailing the cause
6+
// of the failure and index of the Message within a batch.
7+
type SendError struct {
8+
// Index specifies the index of the Message within a batch.
9+
Index uint
10+
Cause error
11+
}
12+
13+
func (err *SendError) Error() string {
14+
return fmt.Sprintf("gomail: could not send email %d: %v",
15+
err.Index+1, err.Cause)
16+
}

send.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (f SendFunc) Send(from string, to []string, msg io.WriterTo) error {
3636
func Send(s Sender, msg ...*Message) error {
3737
for i, m := range msg {
3838
if err := send(s, m); err != nil {
39-
return fmt.Errorf("gomail: could not send email %d: %v", i+1, err)
39+
return &SendError{Cause: err, Index: uint(i)}
4040
}
4141
}
4242

0 commit comments

Comments
 (0)