wneessen / go-mail

📧 Easy to use, yet comprehensive library for sending mails with Go
https://go-mail.dev
MIT License
571 stars 44 forks source link

Improve error handling #168

Open wneessen opened 8 months ago

wneessen commented 8 months ago
          > Since errors are appendable

BTW, the way how code currently does "appending" is really ... bad. I think. As an author of one of (I believe) good errors packages for Go the issue with current approach is that you create a tree of joined errors. Every time you call errors.Join it creates a new error with two child errors.

A better way I think would be to have a slice of errors you append to and join just once at the end (you could even join in defer and set a named return value. errors.Join also discards all nil errors, so you could just be collecting all errors without checking (unless it influences the code flow). I did something similar here. Maybe the best way would be to extract inner loop code to sendOne internal function which returns error as usual. And then you collect errors in the loop and call final errors.Join.

Originally posted by @mitar in https://github.com/wneessen/go-mail/issues/166#issuecomment-1905724083

wneessen commented 8 months ago

Based on this comment by @mitar, this is a placeholder issue to improve the error handling, as it is - as pointed out - sub-par at the moment.