From: Jeff Halter Date: Mon, 27 Nov 2023 21:05:09 +0000 (-0800) Subject: Add missing error handling and logging (#109) X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/d0ba21fc13154c2ffc95829cd064a8e804ea93e3?ds=sidebyside Add missing error handling and logging (#109) --- diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go index 5de2b45..85f85a4 100644 --- a/hotline/transaction_handlers.go +++ b/hotline/transaction_handlers.go @@ -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") diff --git a/hotline/transaction_handlers_test.go b/hotline/transaction_handlers_test.go index 01880f2..525bb88 100644 --- a/hotline/transaction_handlers_test.go +++ b/hotline/transaction_handlers_test.go @@ -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",