Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caught panic: runtime error: index out of range [3] with length 3 #259

Closed
j-mnr opened this issue Sep 15, 2022 · 6 comments
Closed

Caught panic: runtime error: index out of range [3] with length 3 #259

j-mnr opened this issue Sep 15, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@j-mnr
Copy link

j-mnr commented Sep 15, 2022

馃憢 Hello 馃槃

While trying out some components from Bubbles I ran into an issue with the text-area component -- Full example on playground -- there were two things I noticed.

  1. When I used arrow keys the character [ would make itself appear as if I typed it in
  2. When I held down the Down arrow key a panic would happen.
Caught panic:

runtime error: index out of range [2] with length 2

Restoring terminal...

goroutine 1 [running]:
runtime/debug.Stack()
	/usr/lib/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
	/usr/lib/go/src/runtime/debug/stack.go:16 +0x19
github.com/charmbracelet/bubbletea.(*Program).StartReturningModel.func3()
	/home/jay/.local/share/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.21.0/tea.go:371 +0x95
panic({0x526000, 0xc00001b3e0})
	/usr/lib/go/src/runtime/panic.go:890 +0x262
github.com/charmbracelet/bubbles/textarea.(*Model).CursorDown(0xc00013a400)
	/home/jay/.local/share/go/pkg/mod/github.com/charmbracelet/bubbles@v0.14.0/textarea/textarea.go:371 +0x371
github.com/charmbracelet/bubbles/textarea.Model.Update({{0x0, 0x0}, {0xc0000181b0, 0x4}, {0x535f72, 0x13}, 0x1, 0x7e, {{{0xc00006a100, 0x2, ...}, ...}, ...}, ...}, ...)
	/home/jay/.local/share/go/pkg/mod/github.com/charmbracelet/bubbles@v0.14.0/textarea/textarea.go:910 +0x192c
main.model.Update({{{0x0, 0x0}, {0xc0000181b0, 0x4}, {0x535f72, 0x13}, 0x1, 0x7e, {{{...}, {...}, ...}, ...}, ...}, ...}, ...)
	/home/jay/src/go/personal/intros/bubble-tea/main.go:70 +0x40a
github.com/charmbracelet/bubbletea.(*Program).StartReturningModel(0xc00011e0b0)
	/home/jay/.local/share/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.21.0/tea.go:538 +0x123f
github.com/charmbracelet/bubbletea.(*Program).Start(...)
	/home/jay/.local/share/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.21.0/tea.go:547
main.main()
	/home/jay/src/go/personal/intros/bubble-tea/main.go:17 +0x8a

I'm very new to bubbletea but I'm guessing this isn't expected to happen. Here's the entire go.mod file

module shopls

go 1.19

require (
	github.com/charmbracelet/bubbles v0.14.0
	github.com/charmbracelet/bubbletea v0.21.0
)

require (
	github.com/atotto/clipboard v0.1.4 // indirect
	github.com/charmbracelet/lipgloss v0.5.0 // indirect
	github.com/containerd/console v1.0.3 // indirect
	github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
	github.com/mattn/go-isatty v0.0.14 // indirect
	github.com/mattn/go-runewidth v0.0.13 // indirect
	github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect
	github.com/muesli/cancelreader v0.2.0 // indirect
	github.com/muesli/reflow v0.3.0 // indirect
	github.com/muesli/termenv v0.11.1-0.20220212125758-44cd13922739 // indirect
	github.com/rivo/uniseg v0.2.0 // indirect
	golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
	golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
)

Let me know if there's anything you need to know about concerning my terminal or keyboard.

image

@muesli muesli transferred this issue from charmbracelet/bubbletea Sep 27, 2022
@knz
Copy link
Contributor

knz commented Oct 2, 2022

@maaslalani @muesli I believe this is caused by #263 combined with charmbracelet/bubbletea#466.

The problem (as I understand it) is that when an unrecognized input containing control characters is received by bubbletea, it's translated to regular runes and then inserted by textarea (that's charmbracelet/bubbletea#466).

Then the textinput/textarea misbehaves because of #263.

The input key problem will be papered over by charmbracelet/bubbletea#467, but see my note on #263 on a durable fix by sanitizing the input runes (e.g. via the tea.SanitizeRunes function from charmbracelet/bubbletea#397).

@knz
Copy link
Contributor

knz commented Oct 2, 2022

@j-mnr which terminal are you using?

@j-mnr
Copy link
Author

j-mnr commented Oct 2, 2022

alacritty 0.11.0-dev (513e6a90)

@muesli muesli added the bug Something isn't working label Oct 5, 2022
@maaslalani
Copy link
Member

@j-mnr, Is this still an issue for you?

@j-mnr
Copy link
Author

j-mnr commented Mar 2, 2024

Just re-ran my supplied example on my current version of alacritty 0.13.1 (fe2a3c56) and I couldn't reproduce the issue. Looks to be fixed.

@j-mnr j-mnr closed this as completed Mar 2, 2024
@maaslalani
Copy link
Member

Just re-ran my supplied example on my current version of alacritty 0.13.1 (fe2a3c56) and I couldn't reproduce the issue. Looks to be fixed.

Thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants