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

View file

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