zaquestion / lab

Lab wraps Git or Hub, making it simple to clone, fork, and interact with repositories on GitLab
https://zaquestion.github.io/lab
Creative Commons Zero v1.0 Universal
1.11k stars 102 forks source link

cmd/util.go: Fix panic with getUserIDs #828

Closed prarit closed 2 years ago

prarit commented 2 years ago

'lab mr create -a ' panics if someone specifies a username that doesn't exist:

[prarit@prarit kernel-test]$ ~/Other/github/lab/lab mr create -a prarit123456 panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0xc942b8]

goroutine 1 [running]: github.com/zaquestion/lab/cmd.getUserIDs(0xc000242420, 0x1, 0x1, 0xc000034700, 0x0, 0x0) /home/prarit/Other/github/lab/cmd/util.go:662 +0x98 github.com/zaquestion/lab/cmd.runMRCreate(0x14a2940, 0xc0000fe540, 0x0, 0x2) /home/prarit/Other/github/lab/cmd/mr_create.go:347 +0x10e9 github.com/spf13/cobra.(Command).execute(0x14a2940, 0xc0000fe520, 0x2, 0x2, 0x14a2940, 0xc0000fe520) /home/prarit/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:860 +0x2c2 github.com/spf13/cobra.(Command).ExecuteC(0x149c2c0, 0xc0000bc050, 0x5, 0x5) /home/prarit/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:974 +0x375 github.com/spf13/cobra.(*Command).Execute(...) /home/prarit/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:902 github.com/zaquestion/lab/cmd.Execute(0xc000790500) /home/prarit/Other/github/lab/cmd/root.go:218 +0xf5 main.main() /home/prarit/Other/github/lab/main.go:27 +0x74

Fix the panic and output a warning that the username doesn't exist, and continue to create the merge request.

Fixes #827

Reported-by: GitHub User twouters Signed-off-by: Prarit Bhargava prarit@redhat.com

codecov[bot] commented 2 years ago

Codecov Report

Merging #828 (e1e02c4) into master (597c718) will decrease coverage by 0.07%. The diff coverage is 57.14%.

@@            Coverage Diff             @@
##           master     #828      +/-   ##
==========================================
- Coverage   56.24%   56.17%   -0.08%     
==========================================
  Files          77       77              
  Lines        5771     5775       +4     
==========================================
- Hits         3246     3244       -2     
- Misses       2235     2239       +4     
- Partials      290      292       +2     
Impacted Files Coverage Δ
internal/gitlab/gitlab.go 7.64% <0.00%> (ø)
cmd/util.go 74.37% <66.66%> (-0.28%) :arrow_down:
cmd/fork.go 57.89% <0.00%> (-5.27%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 58af7c1...e1e02c4. Read the comment docs.

bmeneg commented 2 years ago

Oh, good catch. LGTM.