nimblebun / wordle-cli

play wordle in your command line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`invalid memory address or nil pointer dereference` on entering a valid word in random mode

maxcutlyp opened this issue · comments

Output:

Caught panic:

runtime error: invalid memory address or nil pointer dereference

Restoring terminal...

goroutine 1 [running]:
runtime/debug.Stack()
	/usr/lib/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
	/usr/lib/go/src/runtime/debug/stack.go:16 +0x19
github.com/charmbracelet/bubbletea.(*Program).StartReturningModel.func3()
	/home/max/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.19.3/tea.go:350 +0x95
panic({0x5c5580, 0x78d9c0})
	/usr/lib/go/src/runtime/panic.go:1047 +0x266
pkg.nimblebun.works/wordle-cli/game.(*AppModel).save(0xc000136780)
	/home/max/git/wordle-cli/game/utils.go:253 +0x27
pkg.nimblebun.works/wordle-cli/game.(*AppModel).enter(0xc000136780)
	/home/max/git/wordle-cli/game/utils.go:164 +0x5ec
pkg.nimblebun.works/wordle-cli/game.(*AppModel).handleKeyDown(0xc000136780, 0xc000000228, {0x0, 0xc0000d0000, 0x0})
	/home/max/git/wordle-cli/game/model.go:114 +0x14d
pkg.nimblebun.works/wordle-cli/game.(*AppModel).Update(0xc00019c000, {0x5d86c0, 0xc000292030})
	/home/max/git/wordle-cli/game/model.go:137 +0x6f
github.com/charmbracelet/bubbletea.(*Program).StartReturningModel(0xc00015a280)
	/home/max/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.19.3/tea.go:534 +0x139c
github.com/charmbracelet/bubbletea.(*Program).Start(...)
	/home/max/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.19.3/tea.go:543
main.startGame({0x5fbfc5, 0x5ef8a1}, 0xc00010af70, 0xc000126600)
	/home/max/git/wordle-cli/main.go:25 +0x54
main.startRandom(<<<<<<<<<<<<0xc00010af70)
	/home/max/git/wordle-cli/main.go:40 +0x26
github.com/urfave/cli/v2.(*Command).Run(0xc00019a240, 0xc000126540)
	/home/max/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/command.go:163 +0x64a
github.com/urfave/cli/v2.(*App).RunContext(0xc000110ea0, {0x64bb90, 0xc00013a010}, {0xc000128000, 0x2, 0x2})
	/home/max/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:313 +0x81e
github.com/urfave/cli/v2.(*App).Run(...)
	/home/max/go/pkg/mod/github.com/urfave/cli/v2@v2.3.0/app.go:224
main.main()
	/home/max/git/wordle-cli/main.go:68 +0x1f9

From reading the code referenced in the stack trace, my guess is that m.SaveData on the first line of save() in game/utils.go is nil, but I haven't used Go before so that's just a guess.

Edit: adding the following -

if (m.SaveData == nil) {
    return
}

to the start of the aforementioned function fixes the problem by not saving the state of random mode games, but I don't know this is the intended behaviour and if it would break other things related to saving because I haven't read enough of the rest of the program. That said, I can submit a pull request if you'd like.

Output of go version: go version go1.17.6 linux/amd64
OS: Manjaro, kernel version: 5.16.7-1-MANJARO

Let me know if there's any other information that would be helpful for me to provide :)