spr icon indicating copy to clipboard operation
spr copied to clipboard

git-spr subcomand panics with invalid memory address

Open jameskyle opened this issue 2 years ago • 7 comments

As in title, any spr command throws a nil pointer error

 git spr update
> git rev-parse --show-toplevel
> git fetch
> git branch --no-color
> git rebase origin/develop --autostash
> github fetch pull requests
> git branch --no-color
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1375c72]

goroutine 1 [running]:
github.com/ejoffe/spr/github/githubclient.(*client).GetInfo(0xc00012af30, {0x152b710, 0xc000122000}, {0x1529600, 0xc00012aee8})
        /Users/runner/work/spr/spr/github/githubclient/client.go:190 +0x112
github.com/ejoffe/spr/spr.(*stackediff).fetchAndGetGitHubInfo(0xc000130e40, {0x152b710, 0xc000122000})
        /Users/runner/work/spr/spr/spr/spr.go:448 +0x158
github.com/ejoffe/spr/spr.(*stackediff).UpdatePullRequests(0xc000130e40, {0x152b710, 0xc000122000}, {0x0, 0x0, 0x0}, 0x0)
        /Users/runner/work/spr/spr/spr/spr.go:113 +0x9b
main.main.func3(0xc000130f60)
        /Users/runner/work/spr/spr/cmd/spr/main.go:143 +0xdf
github.com/urfave/cli/v2.(*Command).Run(0xc0002098c0, 0xc00013f200)
        /Users/runner/go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:163 +0x64a
github.com/urfave/cli/v2.(*App).RunContext(0xc000193040, {0x152b710, 0xc000122000}, {0xc000134000, 0x2, 0x2})
        /Users/runner/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:313 +0x81e
github.com/urfave/cli/v2.(*App).Run(...)
        /Users/runner/go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:224
main.main()
        /Users/runner/work/spr/spr/cmd/spr/main.go:200 +0x1099

I think this might have come with the 0.9.2 upgrade. Will test 0.9.1.

jameskyle avatar Sep 08 '22 20:09 jameskyle

Figured out the cause. In the 0.9.x versions of spr, if the GITHUB_TOKEN is not set it throws this nil pointer instead of providing a warning to stdout like before.

When the GITHUB_TOKEN is set, it does not throw the nil pointer. But git spr update results in a panic: createPullRequest: was submitted too quickly panic.

jameskyle avatar Sep 08 '22 20:09 jameskyle

I have confirmed that none of these issues are present in 0.8.5.

jameskyle avatar Sep 08 '22 20:09 jameskyle

@jameskyle - can you please check if you still have this issue in the latest v0.10.0?

ejoffe avatar Mar 07 '23 00:03 ejoffe

We are still seeing this with VERSION: 0.11.1 : 2023-03-30T17:52:16Z : 96da77ea

aspiers avatar Apr 13 '23 21:04 aspiers

I've hit this today on 0.14.4 😱

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x10254e050]

goroutine 35 [running]:
github.com/ejoffe/spr/github/githubclient.formatStackMarkdown({{0x140000977ec, 0x8}, {0x14000097730, 0x28}, {0x140000977b9, 0x1f}, {0x102655c68, 0x0}, 0x0}, {0x1400033e3e0, ...})
	/Users/runner/work/spr/spr/github/githubclient/client.go:413 +0x60
github.com/ejoffe/spr/github/githubclient.formatBody({{0x140000977ec, 0x8}, {0x14000097730, 0x28}, {0x140000977b9, 0x1f}, {0x102655c68, 0x0}, 0x0}, {0x1400033e3e0?, ...})
	/Users/runner/work/spr/spr/github/githubclient/client.go:433 +0x74
github.com/ejoffe/spr/github/githubclient.(*client).UpdatePullRequest(0x1400000ca50, {0x102739030, 0x102a55460}, {0x102738f50, 0x1400000ca38}, {0x1400033e3e0, 0x3, 0x4}, 0x1400033a540, {{0x140000977ec, ...}, ...}, ...)
	/Users/runner/work/spr/spr/github/githubclient/client.go:524 +0x330
github.com/ejoffe/spr/spr.(*stackediff).UpdatePullRequests.func2(0x0?)
	/Users/runner/work/spr/spr/spr/spr.go:242 +0xcc
created by github.com/ejoffe/spr/spr.(*stackediff).UpdatePullRequests in goroutine 1
	/Users/runner/work/spr/spr/spr/spr.go:240 +0x108c

It seems that removing WIP prefix from commit message helped 🤔

maciektr avatar Dec 01 '23 09:12 maciektr

@maciektr I think your crash is #325.

I ran into this and setting GITHUB_TOKEN as suggested by @jameskyle fixed it for me.

jkuebart avatar Jan 31 '24 16:01 jkuebart

@ejoffe Would it perhaps be possible to utilise git credential to get the token rather than relying on an environment variable? It should be as easy as

printf 'url=%s\n\n' 'https://[email protected]/ejoffe/spr.git' | git credential fill

and parsing the output that looks like

protocol=https
host=github.com
username=ejoffe
password=ghp_***

I think this would be very useful functionality.

jkuebart avatar Feb 01 '24 09:02 jkuebart