[GH-ISSUE #407] Panic when press UP on empty list #298

Closed
opened 2026-03-04 01:03:44 +03:00 by kerem · 0 comments
Owner

Originally created by @BronOS on GitHub (Feb 17, 2020).
Original GitHub issue: https://github.com/rivo/tview/issues/407

There is an panic when list is empty and change function is set up on key press UP:

package main

import "github.com/rivo/tview"

func main() {
	app := tview.NewApplication()
	list := tview.NewList()
	list.SetBorder(true).SetTitle("Panic when press UP on empty list")
	list.SetChangedFunc(func(index int, mainText, secondaryText string, shortcut rune) {
		// empty
	})
	if err := app.SetRoot(list, true).Run(); err != nil {
		panic(err)
	}
}

panic: runtime error: index out of range [-1] [recovered]
panic: runtime error: index out of range [-1]

goroutine 1 [running]:
github.com/rivo/tview.(*Application).Run.func1(0xc0000d8180)
/Users/bronos/Projects/go/src/github.com/BronOS/pkg/mod/github.com/rivo/tview@v0.0.0-20200204110323-ae3d8cac5e4b/application.go:160 +0x82
panic(0x1189ae0, 0xc0003ec000)
/usr/local/go/src/runtime/panic.go:679 +0x1b2
github.com/rivo/tview.(*List).InputHandler.func1(0xc0003e8000, 0xc0003ea010)
/Users/bronos/Projects/go/src/github.com/BronOS/pkg/mod/github.com/rivo/tview@v0.0.0-20200204110323-ae3d8cac5e4b/list.go:547 +0x378
github.com/rivo/tview.(*Box).WrapInputHandler.func1(0xc0003e8000, 0xc0003ea010)
/Users/bronos/Projects/go/src/github.com/BronOS/pkg/mod/github.com/rivo/tview@v0.0.0-20200204110323-ae3d8cac5e4b/box.go:160 +0x5d
github.com/rivo/tview.(*Application).Run(0xc0000d8180, 0x0, 0x0)
/Users/bronos/Projects/go/src/github.com/BronOS/pkg/mod/github.com/rivo/tview@v0.0.0-20200204110323-ae3d8cac5e4b/application.go:245 +0x3c0
main.main()
/Users/bronos/Projects/go/src/github.com/BronOS/tview_test/main.go:12 +0x21b

Originally created by @BronOS on GitHub (Feb 17, 2020). Original GitHub issue: https://github.com/rivo/tview/issues/407 There is an panic when list is empty and change function is set up on key press UP: ```go package main import "github.com/rivo/tview" func main() { app := tview.NewApplication() list := tview.NewList() list.SetBorder(true).SetTitle("Panic when press UP on empty list") list.SetChangedFunc(func(index int, mainText, secondaryText string, shortcut rune) { // empty }) if err := app.SetRoot(list, true).Run(); err != nil { panic(err) } } ``` panic: runtime error: index out of range [-1] [recovered] panic: runtime error: index out of range [-1] goroutine 1 [running]: github.com/rivo/tview.(*Application).Run.func1(0xc0000d8180) /Users/bronos/Projects/go/src/github.com/BronOS/pkg/mod/github.com/rivo/tview@v0.0.0-20200204110323-ae3d8cac5e4b/application.go:160 +0x82 panic(0x1189ae0, 0xc0003ec000) /usr/local/go/src/runtime/panic.go:679 +0x1b2 github.com/rivo/tview.(*List).InputHandler.func1(0xc0003e8000, 0xc0003ea010) /Users/bronos/Projects/go/src/github.com/BronOS/pkg/mod/github.com/rivo/tview@v0.0.0-20200204110323-ae3d8cac5e4b/list.go:547 +0x378 github.com/rivo/tview.(*Box).WrapInputHandler.func1(0xc0003e8000, 0xc0003ea010) /Users/bronos/Projects/go/src/github.com/BronOS/pkg/mod/github.com/rivo/tview@v0.0.0-20200204110323-ae3d8cac5e4b/box.go:160 +0x5d github.com/rivo/tview.(*Application).Run(0xc0000d8180, 0x0, 0x0) /Users/bronos/Projects/go/src/github.com/BronOS/pkg/mod/github.com/rivo/tview@v0.0.0-20200204110323-ae3d8cac5e4b/application.go:245 +0x3c0 main.main() /Users/bronos/Projects/go/src/github.com/BronOS/tview_test/main.go:12 +0x21b
kerem closed this issue 2026-03-04 01:03:44 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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
starred/tview#298
No description provided.