From 416bb6e7b75a1fc2f323228c3d5dbba62b33ebcc Mon Sep 17 00:00:00 2001 From: Martin Dosch Date: Thu, 28 Mar 2024 18:07:23 +0100 Subject: [PATCH] XEP-0478: Be more verbose in error if max stanza size is exceeded. --- xmpp.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/xmpp.go b/xmpp.go index 986a97d..649ac82 100644 --- a/xmpp.go +++ b/xmpp.go @@ -1214,7 +1214,8 @@ func (c *Client) Send(chat Chat) (n int, err error) { stanza := fmt.Sprintf(""+subtext+"%s"+oobtext+thdtext+"\n", xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce(), xmlEscape(chat.Text)) if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes { - return 0, errors.New("max. stanza size exceeded") + return 0, fmt.Errorf("stanza size (%v bytes) exceeds limit (%v bytes)", + len(stanza), c.LimitMaxBytes) } return fmt.Fprint(c.stanzaWriter, stanza) @@ -1236,7 +1237,8 @@ func (c *Client) SendOOB(chat Chat) (n int, err error) { stanza := fmt.Sprintf(""+oobtext+thdtext+"\n", xmlEscape(chat.Remote), xmlEscape(chat.Type), cnonce()) if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes { - return 0, errors.New("max. stanza size exceeded") + return 0, fmt.Errorf("stanza size (%v bytes) exceeds limit (%v bytes)", + len(stanza), c.LimitMaxBytes) } return fmt.Fprint(c.stanzaWriter, stanza) } @@ -1245,7 +1247,8 @@ func (c *Client) SendOOB(chat Chat) (n int, err error) { func (c *Client) SendOrg(org string) (n int, err error) { stanza := fmt.Sprint(org + "\n") if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes { - return 0, errors.New("max. stanza size exceeded") + return 0, fmt.Errorf("stanza size (%v bytes) exceeds limit (%v bytes)", + len(stanza), c.LimitMaxBytes) } return fmt.Fprint(c.stanzaWriter, stanza) } @@ -1293,7 +1296,8 @@ func (c *Client) SendPresence(presence Presence) (n int, err error) { stanza := fmt.Sprintf(buf + "") if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes { - return 0, errors.New("max. stanza size exceeded") + return 0, fmt.Errorf("stanza size (%v bytes) exceeds limit (%v bytes)", + len(stanza), c.LimitMaxBytes) } return fmt.Fprint(c.stanzaWriter, stanza) } @@ -1309,7 +1313,8 @@ func (c *Client) SendHtml(chat Chat) (n int, err error) { "%s\n", xmlEscape(chat.Remote), xmlEscape(chat.Type), xmlEscape(chat.Text), chat.Text) if c.LimitMaxBytes != 0 && len(stanza) > c.LimitMaxBytes { - return 0, errors.New("max. stanza size exceeded") + return 0, fmt.Errorf("stanza size (%v bytes) exceeds limit (%v bytes)", + len(stanza), c.LimitMaxBytes) } return fmt.Fprint(c.stanzaWriter, stanza) }