]> git.r.bdr.sh - rbdr/mobius/commitdiff
Add missing error handling and logging (#109)
authorJeff Halter <redacted>
Mon, 27 Nov 2023 21:05:09 +0000 (13:05 -0800)
committerGitHub <redacted>
Mon, 27 Nov 2023 21:05:09 +0000 (13:05 -0800)
hotline/transaction_handlers.go
hotline/transaction_handlers_test.go

index 5de2b452dec9ab9f7ccb8ae715786e5549e43655..85f85a4ddec59feadb0886427fa4517397cf62be 100644 (file)
@@ -305,7 +305,7 @@ func HandleChatSend(cc *ClientConn, t *Transaction) (res []Transaction, err erro
 func HandleSendInstantMsg(cc *ClientConn, t *Transaction) (res []Transaction, err error) {
        if !cc.Authorize(accessSendPrivMsg) {
                res = append(res, cc.NewErrReply(t, "You are not allowed to send private messages."))
-               return res, err
+               return res, errors.New("user is not allowed to send private messages")
        }
 
        msg := t.GetField(FieldData)
@@ -326,7 +326,10 @@ func HandleSendInstantMsg(cc *ClientConn, t *Transaction) (res []Transaction, er
                reply.Fields = append(reply.Fields, NewField(FieldQuotingMsg, t.GetField(FieldQuotingMsg).Data))
        }
 
-       id, _ := byteToInt(ID.Data)
+       id, err := byteToInt(ID.Data)
+       if err != nil {
+               return res, errors.New("invalid client ID")
+       }
        otherClient, ok := cc.Server.Clients[uint16(id)]
        if !ok {
                return res, errors.New("invalid client ID")
index 01880f2555ceb6db7aa782cbbc4b1fc8b06028d6..525bb8895efe51fc5a391e0367535ba4aefff4b5 100644 (file)
@@ -2438,7 +2438,7 @@ func TestHandleSendInstantMsg(t *testing.T) {
                                        },
                                },
                        },
-                       wantErr: assert.NoError,
+                       wantErr: assert.Error,
                },
                {
                        name: "when client 1 sends a message to client 2",