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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could not decode rune #668

Closed
muesli opened this issue Feb 16, 2023 Discussed in #664 · 5 comments
Closed

could not decode rune #668

muesli opened this issue Feb 16, 2023 Discussed in #664 · 5 comments
Labels
bug Something isn't working

Comments

@muesli
Copy link
Contributor

muesli commented Feb 16, 2023

Discussed in #664

Originally posted by mschneider82 December 5, 2022
i am using the mouse input and always getting a program exit after a while because of "could not decode rune"

I would expect it continues instead of failing on a invalid utf 8 rune.

		r, width := utf8.DecodeRune(b[i:])
		if r == utf8.RuneError {
			return nil, errors.New("could not decode rune")
		}
```</div>
@muesli muesli added the bug Something isn't working label Feb 16, 2023
@muesli
Copy link
Contributor Author

muesli commented Feb 16, 2023

Note: the reason we return an error here, is that this is a bit of a panic situation, as all further decodes would likely fail to.

On the bright side, I believe this is already fixed by @knz and I will soon get to merge that fix.

@j178
Copy link
Contributor

j178 commented Mar 24, 2023

Hi,

I encountered the same problem, here is a minimal reproduction example:

package main

import (
	"log"

	tea "github.com/charmbracelet/bubbletea"
)

type model struct{}

func (model) Init() tea.Cmd {
	return nil
}

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	return m, nil
}

func (model) View() string {
	return "hello world"
}

func main() {
	p := tea.NewProgram(model{})
	log.Fatal(p.Run())
}

When running the program, if you paste below text to the terminal, the program will exit with "could not decode rune" error:

我要你扮演一个侏儒。你会为我提供可以在任何地方进行的活动和爱好的有趣、独特的想法。例如,我可能会向您询问有趣的院子设计建议或在天气不佳时在室内消磨时间的创造性方法。此外,如有必要,您可以建议与我的要求相符的其他相关活动或项目。我的第一个请求是“我正在寻找我所在地区的新户外活动"

Actually this bug can be reproduced in any bubbletea program, if any Chinese text longer than 256 characters is pasted, the program will exit.

@knz
Copy link
Contributor

knz commented Mar 24, 2023

Yep, this is a known issue.

@muesli my PR to handle long inputs should help alleviate this.

@BigJk
Copy link
Contributor

BigJk commented Apr 11, 2023

I encountered a similar problem where I first thought Bubblezone was causing the problem (lrstanley/bubblezone#17). After further investigation it seems Bubbleteas mouse handling with tea.WithMouseAllMotion() is the culprit.

If tea.WithMouseAllMotion() is enabled the whole terminal freezes after a bit of mouse movement. Also when I minimize the console window and restore it, it consistently freezes. I tried this with iterm2 and the default macos terminal. The both won't output the could not decode rune and just be frozen and locked. I have to manually kill them. @lrstanley confirmed that Alacritty (via WSL) shows similar behaviour, but in contrast to iterm2 / macos terminal does output the could not decode rune error.

Reproducible example: lrstanley/bubblezone#17 (comment)

@knz I tried to use your PR with the help of a replace in the go.mod

replace github.com/charmbracelet/bubbletea v0.23.2 => github.com/knz/bubbletea v0.0.0-20230107191255-7b1c10438d90

but even with your fix(key): support very long buffered input the program still freezes.

EDIT: #594 seems to fix the problem 👀

@j178
Copy link
Contributor

j178 commented Jan 2, 2024

Since #570 gets merged, I think this issue is resolved now.

@muesli muesli closed this as completed Mar 1, 2024
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