go-telegram-bot-api/telegram-bot-api

Runtime error

Hasi666 opened this issue · 1 comments

for update := range updates {
    if update.Message != nil {
        text := update.Message.Text
        chatID := update.Message.Chat.ID
        if text == "/start" re.MatchString(text) text == "cancel" {
          match := re.FindStringSubmatch(text)
          referrerID, _ := strconv.Atoi(match[1])
          refral.StartHandler(bot, update, referrerID)
and ....

2024/08/03 11:33:54 Endpoint: getUpdates, params: map[allowed_updates:null offset:489227412 timeout:60]
**panic: runtime error: index out of range [1] with length 0

goroutine 1 [running]:
main.main()
        C:/Users/Afra/Desktop/main.go:39 +0x868
exit status 2**

How fix that and why it happend ?

weezel commented

Without seeing the whole code it's a bit hard to say but here:

  • referrerID, _ := strconv.Atoi(match[1])
  • and on error **panic: runtime error: index out of range [1] with length 0
    => you are trying to access slice index 1 which doesn't exist. Actually length of that slice is 0.