achannarasappa / ticker

Terminal stock ticker with live updates and position tracking
GNU General Public License v3.0
4.98k stars 271 forks source link

Panic when maximizing window #147

Closed viperperidot closed 3 years ago

viperperidot commented 3 years ago

When I start ticker and then maximize the window I get this panic:

Caught panic:

runtime error: slice bounds out of range [:-1]

mk@mk-Inspiron-15-3567:~$ 

goroutine 1 [running]:
runtime/debug.Stack(0x56, 0x0, 0x0)
    /opt/hostedtoolcache/go/1.15.8/x64/src/runtime/debug/stack.go:24 +0x9f
runtime/debug.PrintStack()
    /opt/hostedtoolcache/go/1.15.8/x64/src/runtime/debug/stack.go:16 +0x25
github.com/charmbracelet/bubbletea.(*Program).Start.func1(0xc0001dd290)
    /home/runner/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.12.2/tea.go:119 +0xd3
panic(0x960a40, 0xc000341420)
    /opt/hostedtoolcache/go/1.15.8/x64/src/runtime/panic.go:969 +0x1b9
github.com/achannarasappa/term-grid.getLineText(0x0, 0xc0003998a0, 0x1, 0x1, 0x1, 0xffffffffffffffff, 0x0, 0x1, 0x1)
    /home/runner/go/pkg/mod/github.com/achannarasappa/term-grid@v0.2.0/cell.go:40 +0x251
github.com/achannarasappa/term-grid.getLines(0x0, 0x0, 0xffffffffffffffff, 0x0, 0x0, 0x0, 0xc0002d83e0, 0x2, 0x2, 0x2, ...)
    /home/runner/go/pkg/mod/github.com/achannarasappa/term-grid@v0.2.0/cell.go:74 +0x2d7
github.com/achannarasappa/term-grid.renderRow(0x96, 0xc00024e000, 0xb, 0xc, 0x1, 0xc000046400, 0x0)
    /home/runner/go/pkg/mod/github.com/achannarasappa/term-grid@v0.2.0/row.go:81 +0x1ad
github.com/achannarasappa/term-grid.Render(0xc000258000, 0xf, 0x10, 0x0, 0x1, 0xc0001dcff0, 0x9c4b18)
    /home/runner/go/pkg/mod/github.com/achannarasappa/term-grid@v0.2.0/grid.go:29 +0xcc
github.com/achannarasappa/ticker/internal/ui/component/watchlist.Model.View(0x96, 0xc000155500, 0x5, 0x8, 0xc0001dd8c0, 0x10101, 0x9c4b00, 0x5, 0x0, 0x0, ...)
    /home/runner/work/ticker/ticker/internal/ui/component/watchlist/watchlist.go:85 +0x33a
github.com/achannarasappa/ticker/internal/ui.Model.Update(0x5, 0x0, 0x0, 0x0, 0xc000156900, 0x8, 0x8, 0x101010101, 0x0, 0x0, ...)
    /home/runner/work/ticker/ticker/internal/ui/ui.go:114 +0x765
github.com/charmbracelet/bubbletea.(*Program).Start(0xc0001dd290, 0x0, 0x0)
    /home/runner/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.12.2/tea.go:214 +0x61c
github.com/achannarasappa/ticker/internal/ui.Start.func1(0xc0001dcb70, 0xc0001dcc90)
    /home/runner/work/ticker/ticker/internal/ui/start.go:14 +0x1a5
github.com/achannarasappa/ticker/internal/cli.Run.func1(0xd00c40, 0xd3be70, 0x0, 0x0)
    /home/runner/work/ticker/ticker/internal/cli/cli.go:36 +0x2a
github.com/spf13/cobra.(*Command).execute(0xd00c40, 0xc00001e1d0, 0x0, 0x0, 0xd00c40, 0xc00001e1d0)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:854 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0xd00c40, 0x44570a, 0xcb7dc0, 0xc000042778)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:958 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:895
github.com/achannarasappa/ticker/cmd.Execute()
achannarasappa commented 3 years ago

I'm not able to replicate this issue. Does it happen every time the window is resized to full screen? Do resizes in general also cause it to occur?

viperperidot commented 3 years ago

Yes it happens every time the window is resized, currently I can only use ticker in the size that the terminal launches in otherwise I will get the panic. Yes any resize causes this, even a drag one.

achannarasappa commented 3 years ago

It might be caused by the width of each cell being negative for some reason during a window resize event. I added handling for this - have a look at the latest version and let me know if that fixed it.

viperperidot commented 3 years ago

Unfortunately this update did not fix it..

achannarasappa commented 3 years ago

Any chance you'd be open to trying it in a VM? This would help isolate the issue. If the issue occurs in the VM that great then I can try replicating it on my end with the same setup. If not then it's possible it's a hardware issue of some kind.

Since I can not replicate the issue, it's any fix I attempt would be a shot in a dark.

viperperidot commented 3 years ago

I am not using a VM, but I can say that it was introduced in the previous version, I have been able to resize the window successfully prior to this.

achannarasappa commented 3 years ago

Would you be open to sharing your OS + version and terminal + version?

viperperidot commented 3 years ago

Ubuntu 20.04.2 LTS

GNOME Terminal 3.36.2

MisterCubanSandwich commented 3 years ago

I'm seeing similar behavior in macOS 10.15.7, zsh 5.7.1. If I try to launch ticker at my default size of 120x40, it throws that out of range error, but if I resize my terminal so it's not so wide it works correctly.

120 columns seems to be the threshold where it's broken for me.

achannarasappa commented 3 years ago

@MisterCubanSandwich that's very helpful information. Are saying if the terminal window exceeds 120 columns the error is thrown? @viperperidot does resizing below 120 also work okay for you?

MisterCubanSandwich commented 3 years ago

Correct, it immediately crashes if launched or resized to wider than 120. I can resize it just fine if I keep it narrower than that.

achannarasappa commented 3 years ago

@MisterCubanSandwich would you mind sharing the error message? It would be helpful to understand if it is the exact same issue or a variant

viperperidot commented 3 years ago

@achannarasappa I just tested my threshold and for me I get the error kicking in at 105 column width.

MisterCubanSandwich commented 3 years ago

Here's the error I get on my Mac:

Caught panic:

runtime error: slice bounds out of range [:-3]

Restoring terminal...

goroutine 1 [running]:
runtime/debug.Stack(0x56, 0x0, 0x0)
    /opt/hostedtoolcache/go/1.15.8/x64/src/runtime/debug/stack.go:24 +0x9f
runtime/debug.PrintStack()
    /opt/hostedtoolcache/go/1.15.8/x64/src/runtime/debug/stack.go:16 +0x25
github.com/charmbracelet/bubbletea.(*Program).Start.func1(0xc000153080)
    /home/runner/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.12.2/tea.go:119 +0xd3
panic(0x1560da0, 0xc00029d020)
    /opt/hostedtoolcache/go/1.15.8/x64/src/runtime/panic.go:969 +0x1b9
github.com/achannarasappa/term-grid.getLineText(0x0, 0xc00031c650, 0x1, 0x1, 0x1, 0xfffffffffffffffd, 0x0, 0x1, 0x1)
    /home/runner/go/pkg/mod/github.com/achannarasappa/term-grid@v0.2.0/cell.go:40 +0x251
github.com/achannarasappa/term-grid.getLines(0x0, 0x0, 0xfffffffffffffffd, 0x0, 0x0, 0x0, 0xc00000c3c0, 0x2, 0x2, 0x2, ...)
    /home/runner/go/pkg/mod/github.com/achannarasappa/term-grid@v0.2.0/cell.go:74 +0x2d7
github.com/achannarasappa/term-grid.renderRow(0x79, 0xc000262000, 0x9, 0x9, 0x1, 0xc00003d680, 0x0)
    /home/runner/go/pkg/mod/github.com/achannarasappa/term-grid@v0.2.0/row.go:81 +0x1ad
github.com/achannarasappa/term-grid.Render(0xc000132000, 0x6, 0x8, 0x0, 0x1, 0xc000152e40, 0x15c5318)
    /home/runner/go/pkg/mod/github.com/achannarasappa/term-grid@v0.2.0/grid.go:29 +0xcc
github.com/achannarasappa/ticker/internal/ui/component/watchlist.Model.View(0x79, 0xc00051c280, 0x2, 0x2, 0xc0000685a0, 0x10101, 0x15c52e8, 0x5, 0xc0000a6b00, 0x2, ...)
    /home/runner/work/ticker/ticker/internal/ui/component/watchlist/watchlist.go:85 +0x33a
github.com/achannarasappa/ticker/internal/ui.Model.Update(0x5, 0xc0000a6b00, 0x2, 0x2, 0x0, 0x0, 0x0, 0x10101, 0x0, 0x0, ...)
    /home/runner/work/ticker/ticker/internal/ui/ui.go:114 +0x765
github.com/charmbracelet/bubbletea.(*Program).Start(0xc000153080, 0x0, 0x0)
    /home/runner/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.12.2/tea.go:214 +0x61c
github.com/achannarasappa/ticker/internal/ui.Start.func1(0xc000152a80, 0xc000152b70)
    /home/runner/work/ticker/ticker/internal/ui/start.go:14 +0x1a5
github.com/achannarasappa/ticker/internal/cli.Run.func1(0x1906e60, 0x1941c48, 0x0, 0x0)
    /home/runner/work/ticker/ticker/internal/cli/cli.go:36 +0x2a
github.com/spf13/cobra.(*Command).execute(0x1906e60, 0xc00008e1b0, 0x0, 0x0, 0x1906e60, 0xc00008e1b0)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:854 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0x1906e60, 0x1044aaa, 0x18be180, 0xc000038778)
    /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.1.1/command.go:958 +0x375
achannarasappa commented 3 years ago

Thanks @viperperidot and @MisterCubanSandwich this info is really helpful. I'll take a shot at replicating the error

achannarasappa commented 3 years ago

Thanks for the details @viperperidot and @MisterCubanSandwich. I've put out a fix in release v4.0.4 that I believe addresses the issue. The root cause was that the width of the fixed width cells sometimes exceeded with width of the row which cause the error both of you observed. I've added better handling for this condition now and hopefully it will work as expected. When you have a chance take a look and let me know if the issue still occurs (and if it does please reshare the new error).

achannarasappa commented 3 years ago

Good news is I can now replicate the bug, bad news is that the bug is not fixed :)

It seems to occur on window resize frequently enough to be annoying but not on every resize. I'll keep at a fix

achannarasappa commented 3 years ago

Thanks for the comment @spsx ! I'll close this issue but do reopen if the issue still resurfaces