Why clog the code with uhOh, it panics anyway

This commit is contained in:
Bohdan Horbeshko 2025-06-14 14:34:51 -04:00
parent ebdf180ce5
commit 9ed3a8b875
2 changed files with 14 additions and 60 deletions

View file

@ -16,10 +16,6 @@ import (
"github.com/zelenin/go-tdlib/client"
)
func uhOh() {
log.Fatal("Update type mismatch")
}
func int64SliceToStringSlice(ints []int64) []string {
strings := make([]string, len(ints))
wg := sync.WaitGroup{}
@ -89,89 +85,50 @@ func (c *Client) updateHandler() {
if update.GetClass() == client.ClassUpdate {
switch update.GetType() {
case client.TypeUpdateUser:
typedUpdate, ok := update.(*client.UpdateUser)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateUser)
c.updateUser(typedUpdate)
log.Debugf("%#v", typedUpdate.User)
case client.TypeUpdateUserStatus:
typedUpdate, ok := update.(*client.UpdateUserStatus)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateUserStatus)
c.updateUserStatus(typedUpdate)
log.Debugf("%#v", typedUpdate.Status)
case client.TypeUpdateNewChat:
typedUpdate, ok := update.(*client.UpdateNewChat)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateNewChat)
c.updateNewChat(typedUpdate)
log.Debugf("%#v", typedUpdate.Chat)
case client.TypeUpdateChatPosition:
typedUpdate, ok := update.(*client.UpdateChatPosition)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateChatPosition)
c.updateChatPosition(typedUpdate)
log.Debugf("%#v", typedUpdate)
case client.TypeUpdateChatLastMessage:
typedUpdate, ok := update.(*client.UpdateChatLastMessage)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateChatLastMessage)
c.updateChatLastMessage(typedUpdate)
log.Debugf("%#v", typedUpdate)
case client.TypeUpdateNewMessage:
typedUpdate, ok := update.(*client.UpdateNewMessage)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateNewMessage)
c.updateNewMessage(typedUpdate)
log.Debugf("%#v", typedUpdate.Message)
case client.TypeUpdateMessageContent:
typedUpdate, ok := update.(*client.UpdateMessageContent)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateMessageContent)
c.updateMessageContent(typedUpdate)
log.Debugf("%#v", typedUpdate.NewContent)
case client.TypeUpdateDeleteMessages:
typedUpdate, ok := update.(*client.UpdateDeleteMessages)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateDeleteMessages)
c.updateDeleteMessages(typedUpdate)
case client.TypeUpdateAuthorizationState:
typedUpdate, ok := update.(*client.UpdateAuthorizationState)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateAuthorizationState)
c.updateAuthorizationState(typedUpdate)
case client.TypeUpdateMessageSendSucceeded:
typedUpdate, ok := update.(*client.UpdateMessageSendSucceeded)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateMessageSendSucceeded)
c.updateMessageSendSucceeded(typedUpdate)
case client.TypeUpdateMessageSendFailed:
typedUpdate, ok := update.(*client.UpdateMessageSendFailed)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateMessageSendFailed)
c.updateMessageSendFailed(typedUpdate)
case client.TypeUpdateChatTitle:
typedUpdate, ok := update.(*client.UpdateChatTitle)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateChatTitle)
c.updateChatTitle(typedUpdate)
case client.TypeUpdateChatReadOutbox:
typedUpdate, ok := update.(*client.UpdateChatReadOutbox)
if !ok {
uhOh()
}
typedUpdate, _ := update.(*client.UpdateChatReadOutbox)
c.updateChatReadOutbox(typedUpdate)
default:
// log only handled types

View file

@ -2119,10 +2119,7 @@ func (c *Client) getNLastMessages(chatID int64, limit *MessageLimit) ([]*client.
case MessageLimitChars:
// rough but why care
if message.Content != nil && message.Content.MessageContentType() == client.TypeMessageText {
textContent, ok := message.Content.(*client.MessageText)
if !ok {
uhOh()
}
textContent, _ := message.Content.(*client.MessageText)
if textContent.Text != nil {
charsCount += len(textContent.Text.Text)