Refactor error handling in message sending loop

Changed from range over messages to range with index to correctly update sendError field in the original messages slice. This prevents shadowing issues and ensures proper error logging for each message.
This commit is contained in:
Winni Neessen 2024-09-18 12:29:42 +02:00
parent ee726487f1
commit 8ee37abca2
Signed by: wneessen
GPG key ID: 5F3AF39B820C119D

View file

@ -24,9 +24,9 @@ func (c *Client) Send(messages ...*Msg) (returnErr error) {
returnErr = errors.Join(errs...)
}()
for _, message := range messages {
for id, message := range messages {
if sendErr := c.sendSingleMsg(message); sendErr != nil {
message.sendError = sendErr
messages[id].sendError = sendErr
errs = append(errs, sendErr)
}
}