Describe the bug
Calling ProgressBarState.String() appears to panic when the receiver value is outside the [0, 4] range.
The method looks like this:
func (s ProgressBarState) String() string {
return [...]string{
"None",
"Default",
"Error",
"Indeterminate",
"Warning",
}[s]
}
ProgressBarState is defined as type ProgressBarState int, and only five constants (0–4) are defined. The array literal is fixed at length 5 and indexed directly with s, so a value outside that range might cause an index-out-of-range panic.
ProgressBar.State is also an exported field, so it might be possible to assign arbitrary values without going through the NewProgressBar constructor.
Setup
- OS: not terminal-specific
- Shell: not terminal-specific
- Terminal Emulator: not terminal-specific
- Terminal Multiplexer: not terminal-specific
The issue appears to be in pure Go runtime code, unrelated to terminal environment.
To Reproduce
- Create a file
main.go with the following content:
package main
import tea "charm.land/bubbletea/v2"
func main() {
var s tea.ProgressBarState = 5
println(s.String())
}
-
Run go run main.go
-
Observe the output:
panic: runtime error: index out of range [5] with length 5
Negative values seem to behave similarly — replacing 5 with -1 produces:
panic: runtime error: index out of range [-1]
Source Code
// tea.go, around line 321
func (s ProgressBarState) String() string {
return [...]string{
"None",
"Default",
"Error",
"Indeterminate",
"Warning",
}[s]
}
Expected behavior
Unsure if this is intentional. The method might simply never be called with unexpected values in practice, in which case this is a non-issue. If out-of-range inputs are a realistic concern, some bounds protection might be needed so the method doesn't panic.
Screenshots
N/A
Additional context
N/A
Describe the bug
Calling
ProgressBarState.String()appears to panic when the receiver value is outside the[0, 4]range.The method looks like this:
ProgressBarStateis defined astype ProgressBarState int, and only five constants (0–4) are defined. The array literal is fixed at length 5 and indexed directly withs, so a value outside that range might cause an index-out-of-range panic.ProgressBar.Stateis also an exported field, so it might be possible to assign arbitrary values without going through theNewProgressBarconstructor.Setup
The issue appears to be in pure Go runtime code, unrelated to terminal environment.
To Reproduce
main.gowith the following content:Run
go run main.goObserve the output:
Negative values seem to behave similarly — replacing
5with-1produces:Source Code
Expected behavior
Unsure if this is intentional. The method might simply never be called with unexpected values in practice, in which case this is a non-issue. If out-of-range inputs are a realistic concern, some bounds protection might be needed so the method doesn't panic.
Screenshots
N/A
Additional context
N/A