Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix panic on Ctrl+Arrow #63

Merged
merged 1 commit into from
Jul 3, 2022
Merged

Conversation

voidshard
Copy link

@voidshard voidshard commented Jul 2, 2022

I often hit fn+arrow up / down to page up / down. If I accidentally hit ctrl gomu panics :(

Investigated it today and the issue is the rune extraction -- it assumes we'll always have Ctrl+ followed by a single rune, but in the case of an arrow key we have Ctrl+Up or Ctrl+Down so the regex matches nothing & returns an empty list.

Essentially this simply checks if the regex found any matches, if not we return no result akin to a failed map lookup. I considered raising an error, but that would be just as annoying as a panic when I fat finger Ctrl :)

panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/rivo/tview.(*Application).Run.func1()
	/home/augustus/go/pkg/mod/github.com/rivo/tview@v0.0.0-20210312174852-ae9464cc3598/application.go:243 +0x4d
panic({0xadb840, 0xc00076a000})
	/usr/local/go/src/runtime/panic.go:1038 +0x215
github.com/issadarkthing/gomu/anko.extractCtrlRune({0xc00003cc90, 0x9})
	/home/augustus/go/src/github.com/issadarkthing/gomu/anko/anko.go:216 +0x75
github.com/issadarkthing/gomu/anko.(*Anko).KeybindExists(0xb23243, {0xb2591b, 0x6}, 0xc00007e040)
	/home/augustus/go/src/github.com/issadarkthing/gomu/anko/anko.go:158 +0x78
main.start.func4(0xc00007e040)
	/home/augustus/go/src/github.com/issadarkthing/gomu/start.go:516 +0x14b
github.com/rivo/tview.(*Application).Run(0xc00023e2a0)
	/home/augustus/go/pkg/mod/github.com/rivo/tview@v0.0.0-20210312174852-ae9464cc3598/application.go:318 +0x6d2
main.start(0xc00023e2a0, {0xc00028e840, 0xc00003d4b6, 0xc00028e850, 0xc00003d4b7})
	/home/augustus/go/src/github.com/issadarkthing/gomu/start.go:546 +0xceb
main.main()
	/home/augustus/go/src/github.com/issadarkthing/gomu/main.go:21 +0x10e

I often hit fn+arrow up / down to page up / down. If I accidentally
hit ctrl gomu panics.

Investigated it today and the issue is the rune extraction -- it assumes
we'll always have Ctrl+<rune> but in the case of an arrow key we have
Ctrl+Up or Ctrl+Down.

Essentially this simply checks if the regex found any matches, if not we
return not result akin to a failed map lookup. I considered raising an
error, but that would be just as annoying as a panic when I fat finger
Ctrl :)

```golang
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/rivo/tview.(*Application).Run.func1()
	/home/augustus/go/pkg/mod/github.com/rivo/tview@v0.0.0-20210312174852-ae9464cc3598/application.go:243 +0x4d
panic({0xadb840, 0xc00076a000})
	/usr/local/go/src/runtime/panic.go:1038 +0x215
github.com/issadarkthing/gomu/anko.extractCtrlRune({0xc00003cc90, 0x9})
	/home/augustus/go/src/github.com/issadarkthing/gomu/anko/anko.go:216 +0x75
github.com/issadarkthing/gomu/anko.(*Anko).KeybindExists(0xb23243, {0xb2591b, 0x6}, 0xc00007e040)
	/home/augustus/go/src/github.com/issadarkthing/gomu/anko/anko.go:158 +0x78
main.start.func4(0xc00007e040)
	/home/augustus/go/src/github.com/issadarkthing/gomu/start.go:516 +0x14b
github.com/rivo/tview.(*Application).Run(0xc00023e2a0)
	/home/augustus/go/pkg/mod/github.com/rivo/tview@v0.0.0-20210312174852-ae9464cc3598/application.go:318 +0x6d2
main.start(0xc00023e2a0, {0xc00028e840, 0xc00003d4b6, 0xc00028e850, 0xc00003d4b7})
	/home/augustus/go/src/github.com/issadarkthing/gomu/start.go:546 +0xceb
main.main()
	/home/augustus/go/src/github.com/issadarkthing/gomu/main.go:21 +0x10e
```
@issadarkthing
Copy link
Owner

Thank you very much for contributing!

@issadarkthing issadarkthing reopened this Jul 3, 2022
@issadarkthing issadarkthing merged commit cda14ff into issadarkthing:master Jul 3, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants