pulls panic if there is no open pull requests #17

Closed
opened 2019-04-19 06:54:53 +00:00 by lunny · 6 comments
Owner

Author: @quantonganh

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

goroutine 1 [running]:
code.gitea.io/tea/cmd.runPulls(0xc000106f20, 0xc0001e2000, 0xc000106f20)
	/Users/quanta/go/src/code.gitea.io/tea/cmd/pulls.go:52 +0x363
github.com/urfave/cli.HandleAction(0x155c680, 0x163e5f8, 0xc000106f20, 0x0, 0xc000086ba0)
	/Users/quanta/go/src/github.com/urfave/cli/app.go:502 +0xbe
github.com/urfave/cli.Command.Run(0x161dc87, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x162e67d, 0x24, 0x0, ...)
	/Users/quanta/go/src/github.com/urfave/cli/command.go:165 +0x420
github.com/urfave/cli.(*App).Run(0xc0001c2380, 0xc0000b6000, 0x4, 0x4, 0x0, 0x0)
	/Users/quanta/go/src/github.com/urfave/cli/app.go:259 +0x6cf
main.main()
	/Users/quanta/go/src/code.gitea.io/tea/main.go:43 +0x264

The reason is: https://github.com/go-gitea/go-sdk/issues/161

Author: @quantonganh ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x14ece93] goroutine 1 [running]: code.gitea.io/tea/cmd.runPulls(0xc000106f20, 0xc0001e2000, 0xc000106f20) /Users/quanta/go/src/code.gitea.io/tea/cmd/pulls.go:52 +0x363 github.com/urfave/cli.HandleAction(0x155c680, 0x163e5f8, 0xc000106f20, 0x0, 0xc000086ba0) /Users/quanta/go/src/github.com/urfave/cli/app.go:502 +0xbe github.com/urfave/cli.Command.Run(0x161dc87, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x162e67d, 0x24, 0x0, ...) /Users/quanta/go/src/github.com/urfave/cli/command.go:165 +0x420 github.com/urfave/cli.(*App).Run(0xc0001c2380, 0xc0000b6000, 0x4, 0x4, 0x0, 0x0) /Users/quanta/go/src/github.com/urfave/cli/app.go:259 +0x6cf main.main() /Users/quanta/go/src/code.gitea.io/tea/main.go:43 +0x264 ``` The reason is: https://github.com/go-gitea/go-sdk/issues/161
Author
Owner

Author: @lunny

Cannot reproduce here.

➜  log git:(master) pwd
/Users/lunny/gopath/src/gitea.com/lunny/log
➜  log git:(master) tea pulls
No pull requests left
➜  log git:(master) tea login
Name	URL	SSHHost
try	https://try.gitea.io	try.gitea.io
gitea	https://gitea.com	gitea.com
Author: @lunny Cannot reproduce here. ``` ➜ log git:(master) pwd /Users/lunny/gopath/src/gitea.com/lunny/log ➜ log git:(master) tea pulls No pull requests left ➜ log git:(master) tea login Name URL SSHHost try https://try.gitea.io try.gitea.io gitea https://gitea.com gitea.com ```
Author
Owner

Author: @quantonganh

Look at the error, it happened at this line: fb52920af9/cmd/pulls.go (L52)

The main problem is ListPullRequestsOptions does not work. Instead of just list open pull requests, it list all.

In your repo, just

  • create a PR
  • merged
  • tea pulls

to see it show all closed/merged PRs.

Author: @quantonganh Look at the error, it happened at this line: https://github.com/go-gitea/tea/blob/fb52920af9254e5746997c57745fc11b804106da/cmd/pulls.go#L52 The main problem is `ListPullRequestsOptions` does not work. Instead of just list open pull requests, it list all. In your repo, just - create a PR - merged - `tea pulls` to see it show all closed/merged PRs.
Author
Owner

Author: @root360-AndreasUlm

I can reproduce this behaviour.

Printing the resulting addresses of ListRepoPullRequests when the error happens you get:

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

The access to the 3rd element then raises the panic.

After adding a 'nil'-check the panic is not raised:

diff --git a/cmd/pulls.go b/cmd/pulls.go
index 7fe7d8b..43e6245 100644
--- a/cmd/pulls.go
+++ b/cmd/pulls.go
@@ -49,6 +49,9 @@ func runPulls(ctx *cli.Context) error {
        }
 
        for _, pr := range prs {
+               if pr == nil {
+                       continue
+               }
                name := pr.Poster.FullName
                if len(name) == 0 {
                        name = pr.Poster.UserName
Author: @root360-AndreasUlm I can reproduce this behaviour. Printing the resulting addresses of ListRepoPullRequests when the error happens you get: ```[0xc00016a140 0xc00016a3c0 <nil> <nil> <nil> 0xc00016a500 0xc00016a640 0xc00016a780 0xc00016a8c0 0xc00016aa00 0xc00016ab40 0xc00016ac80 0xc00016adc0 0xc00016af00 0xc00016b540 0xc00016b680 0xc00016b7c0 0xc00016b900 0xc00016ba40 0xc00016bb80 0xc00016bcc0 0xc00016be00 0xc000426000 0xc000426140 0xc000426280 0xc0004263c0 0xc000426500 0xc000426640 0xc000426780 0xc0004268c0 0xc000426a00 0xc000426b40 0xc000426c80 0xc000426dc0 0xc000426f00 0xc000427040 0xc000427180 0xc0004272c0 0xc000427400 0xc000427540] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x8f9aea] ... ``` The access to the 3rd element then raises the panic. After adding a 'nil'-check the panic is not raised: ``` diff --git a/cmd/pulls.go b/cmd/pulls.go index 7fe7d8b..43e6245 100644 --- a/cmd/pulls.go +++ b/cmd/pulls.go @@ -49,6 +49,9 @@ func runPulls(ctx *cli.Context) error { } for _, pr := range prs { + if pr == nil { + continue + } name := pr.Poster.FullName if len(name) == 0 { name = pr.Poster.UserName ```
Author
Owner

Author: @lunny

@root360-AndreasUlm could you send a PR to fix that?

Author: @lunny @root360-AndreasUlm could you send a PR to fix that?
Author
Owner

Author: @root360-AndreasUlm

@lunny I'll send a PR today

Author: @root360-AndreasUlm @lunny I'll send a PR today
Author
Owner
Author: @root360-AndreasUlm @lunny created PR https://github.com/go-gitea/tea/pull/18
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: gitea/tea#17
No description provided.