Hi, I’m playing around with the Telegram Bot API, using this library. What happens when I attempt to GetUpdates is the following:
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x10 pc=0x49c0ed]
goroutine 1 [running]:
net/http.(*Client).doFollowingRedirects(0x0, 0xc820162000, 0x866630, 0x0, 0x0, 0x0)
/usr/lib/go/src/net/http/client.go:313 +0x6d
net/http.(*Client).Post(0x0, 0xc8200bcc00, 0x27, 0x81b380, 0x21, 0x7f8f833a95e0, 0xc8200c05c0, 0xc8200e0230, 0x0, 0x0)
/usr/lib/go/src/net/http/client.go:471 +0x107
net/http.(*Client).PostForm(0x0, 0xc8200bcc00, 0x27, 0xc8200bcbd0, 0x2, 0x0, 0x0)
/usr/lib/go/src/net/http/client.go:497 +0x108
github.com/Syfaro/telegram-bot-api.(*BotAPI).MakeRequest(0x987920, 0x7d2e80, 0xa, 0xc8200bcbd0, 0xc8200bcb00, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
/home/vagrant/goenv/src/github.com/Syfaro/telegram-bot-api/methods.go:197 +0x251
github.com/Syfaro/telegram-bot-api.(*BotAPI).GetUpdates(0x987920, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/home/vagrant/goenv/src/github.com/Syfaro/telegram-bot-api/methods.go:997 +0x501
main.GetUpdates()
/home/vagrant/goenv/src/github.com/TheHowl/boorugram2/main.go:44 +0x80
main.main()
/home/vagrant/goenv/src/github.com/TheHowl/boorugram2/main.go:35 +0x3d5
Here’s the code from line 42 to 49:
func GetUpdates() {
UpdateConfig := tgbotapi.NewUpdate(lastUpdate)
Updates, err := bot.GetUpdates(UpdateConfig) // L44
if err != nil {
panic(err)
}
go IterateUpdates(Updates)
}
lastUpdate
is an integer containing the highest offset of the updates already received, that is given to the function to avoid getting duplicate updates from the Telegram Bot API.
I sincerely have no clue of what this is happening. I tried to track down to the Go HTTP request library, and this is where the panic seems to be happening:
func (c *Client) doFollowingRedirects(ireq *Request, shouldRedirect func(int) bool) (resp *Response, err error) {
var base *url.URL
redirectChecker := c.CheckRedirect // L313
if redirectChecker == nil {
redirectChecker = defaultCheckRedirect
}
Nothing that suggests why the error is happening, nor how to troubleshoot it.
The incriminated code of the bot library seems to be fine, too:
func (bot *BotAPI) MakeRequest(endpoint string, params url.Values) (APIResponse, error) {
resp, err := bot.Client.PostForm(fmt.Sprintf(APIEndpoint, bot.Token, endpoint), params) // L197
if err != nil {
return APIResponse{}, err
}
defer resp.Body.Close()