nickvanw / ircx

Basic callback-driven Go IRC bot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

go-kit logger rewrite causes nil dereference panics

mvdan opened this issue · comments

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x5d5a9e]

goroutine 21 [running]:
github.com/go-kit/kit/log.(*context).Log(0xc0003ea030, 0xc0003de040, 0x4, 0x4, 0x0, 0x0)
        /home/mvdan/go/land/src/github.com/go-kit/kit/log/log.go:124 +0x19e
github.com/nickvanw/ircx.(*Bot).ReadLoop(0xc0000e62c0, 0x0, 0x0)
        /home/mvdan/go/land/src/github.com/nickvanw/ircx/bot.go:147 +0x5c
created by github.com/nickvanw/ircx.(*Bot).Connect
        /home/mvdan/go/land/src/github.com/nickvanw/ircx/bot.go:78 +0x8e5

This is presumably because New doesn't set a logger, and other funcs use b.log directly without falling back to the default logger if none is set.

I still think the dependency should be dropped (see #27), but for now it should at least be fixed.

The source code is at https://github.com/mvdan/gibot/tree/4bd39e6cc4e62d66b15589dbe3d339fb04ebe93b - in particular, main.go.

Adding a SetLogger below New did indeed work around this:

bot := ircx.New(config.Server, config.Nick, ircConfig)
bot.SetLogger(bot.Logger())

Bump @nickvanw? It would also be good to convert this project to a Go module.