mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-24 14:40:49 +01:00
Refactor error handling for nil template pointers
Replace fmt.Errorf with errors.New for consistency in error handling. This change ensures a more streamlined and uniform error reporting approach across the codebase. Also updated a test case from t.Errorf to t.Error for better readability.
This commit is contained in:
parent
84b5ebcebc
commit
590dfe97e7
3 changed files with 9 additions and 9 deletions
|
@ -5,7 +5,7 @@
|
|||
package mail
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
|
@ -26,7 +26,7 @@ var newlineBytes = []byte(SingleNewLine)
|
|||
// line length is reached
|
||||
func (l *Base64LineBreaker) Write(data []byte) (numBytes int, err error) {
|
||||
if l.out == nil {
|
||||
err = fmt.Errorf(ErrNoOutWriter)
|
||||
err = errors.New(ErrNoOutWriter)
|
||||
return
|
||||
}
|
||||
if l.used+len(data) < MaxBodyLength {
|
||||
|
|
12
msg.go
12
msg.go
|
@ -743,7 +743,7 @@ func (m *Msg) SetBodyWriter(
|
|||
// The content type will be set to text/html automatically
|
||||
func (m *Msg) SetBodyHTMLTemplate(tpl *ht.Template, data interface{}, opts ...PartOption) error {
|
||||
if tpl == nil {
|
||||
return fmt.Errorf(errTplPointerNil)
|
||||
return errors.New(errTplPointerNil)
|
||||
}
|
||||
buffer := bytes.Buffer{}
|
||||
if err := tpl.Execute(&buffer, data); err != nil {
|
||||
|
@ -758,7 +758,7 @@ func (m *Msg) SetBodyHTMLTemplate(tpl *ht.Template, data interface{}, opts ...Pa
|
|||
// The content type will be set to text/plain automatically
|
||||
func (m *Msg) SetBodyTextTemplate(tpl *tt.Template, data interface{}, opts ...PartOption) error {
|
||||
if tpl == nil {
|
||||
return fmt.Errorf(errTplPointerNil)
|
||||
return errors.New(errTplPointerNil)
|
||||
}
|
||||
buf := bytes.Buffer{}
|
||||
if err := tpl.Execute(&buf, data); err != nil {
|
||||
|
@ -790,7 +790,7 @@ func (m *Msg) AddAlternativeWriter(
|
|||
// The content type will be set to text/html automatically
|
||||
func (m *Msg) AddAlternativeHTMLTemplate(tpl *ht.Template, data interface{}, opts ...PartOption) error {
|
||||
if tpl == nil {
|
||||
return fmt.Errorf(errTplPointerNil)
|
||||
return errors.New(errTplPointerNil)
|
||||
}
|
||||
buffer := bytes.Buffer{}
|
||||
if err := tpl.Execute(&buffer, data); err != nil {
|
||||
|
@ -805,7 +805,7 @@ func (m *Msg) AddAlternativeHTMLTemplate(tpl *ht.Template, data interface{}, opt
|
|||
// The content type will be set to text/plain automatically
|
||||
func (m *Msg) AddAlternativeTextTemplate(tpl *tt.Template, data interface{}, opts ...PartOption) error {
|
||||
if tpl == nil {
|
||||
return fmt.Errorf(errTplPointerNil)
|
||||
return errors.New(errTplPointerNil)
|
||||
}
|
||||
buffer := bytes.Buffer{}
|
||||
if err := tpl.Execute(&buffer, data); err != nil {
|
||||
|
@ -1314,7 +1314,7 @@ func fileFromReadSeeker(name string, reader io.ReadSeeker) *File {
|
|||
// fileFromHTMLTemplate returns a File pointer form a given html/template.Template
|
||||
func fileFromHTMLTemplate(name string, tpl *ht.Template, data interface{}) (*File, error) {
|
||||
if tpl == nil {
|
||||
return nil, fmt.Errorf(errTplPointerNil)
|
||||
return nil, errors.New(errTplPointerNil)
|
||||
}
|
||||
buffer := bytes.Buffer{}
|
||||
if err := tpl.Execute(&buffer, data); err != nil {
|
||||
|
@ -1326,7 +1326,7 @@ func fileFromHTMLTemplate(name string, tpl *ht.Template, data interface{}) (*Fil
|
|||
// fileFromTextTemplate returns a File pointer form a given text/template.Template
|
||||
func fileFromTextTemplate(name string, tpl *tt.Template, data interface{}) (*File, error) {
|
||||
if tpl == nil {
|
||||
return nil, fmt.Errorf(errTplPointerNil)
|
||||
return nil, errors.New(errTplPointerNil)
|
||||
}
|
||||
buffer := bytes.Buffer{}
|
||||
if err := tpl.Execute(&buffer, data); err != nil {
|
||||
|
|
|
@ -122,7 +122,7 @@ func TestMsgWriter_writeMsg(t *testing.T) {
|
|||
em += fmt.Sprintf("* incorrect %q field", ea[e])
|
||||
}
|
||||
em += fmt.Sprintf("\n\nFull message:\n%s", ms)
|
||||
t.Errorf(em)
|
||||
t.Error(em)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue