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

Error from body writer is ignored #81

Closed
oschwald opened this issue Nov 18, 2022 · 2 comments · Fixed by #82
Closed

Error from body writer is ignored #81

oschwald opened this issue Nov 18, 2022 · 2 comments · Fixed by #82
Assignees
Labels
bug Something isn't working

Comments

@oschwald
Copy link

Description

If you set a body writer with SetBodyWriter and the writer fails with an error, (*Msg).WriteTo will not return an error itself.

To Reproduce

Run:

package main

import (
	"errors"
	"fmt"
	"io"

	"github.com/wneessen/go-mail"
)

func main() {
	m := mail.NewMsg()

	m.SetBodyWriter(
		mail.TypeTextPlain,
		func(io.Writer) (int64, error) {
			return 0, errors.New("failed!")
		},
	)

	_, err := m.WriteTo(io.Discard)
	fmt.Println(err)
}

Expected behaviour

The above prints out <nil>. I would expect the body writer error to cause WriteTo to return an error, resulting in the program outputting failed! or a wrapped version of it. Right now, there is no indication that an error occurred.

Screenshots

No response

Attempted Fixes

No response

Additional context

No response

@oschwald oschwald added the bug Something isn't working label Nov 18, 2022
@wneessen wneessen self-assigned this Nov 18, 2022
@wneessen
Copy link
Owner

Thanks for the report. That indeed doesn't sound right. I'll have a look what's going on there.

wneessen added a commit that referenced this issue Nov 19, 2022
The error handling in the msgWriter.writeBody() method was not working properly. We basically overwrote the mw.err with nil if the function that followed after a failed write attempt was successful again

This patch fixes #81
@wneessen wneessen linked a pull request Nov 19, 2022 that will close this issue
wneessen added a commit that referenced this issue Nov 19, 2022
…-is-ignored

#81: Fix error handling in body writer
@oschwald
Copy link
Author

Thanks for the quick fix on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants