ericm / stonks

Stonks is a terminal based stock visualizer and tracker that displays realtime stocks in graph format in a terminal. See how fast your stonks will crash.
https://stonks.icu
GNU General Public License v3.0
544 stars 35 forks source link

Intervals of 1m, 2m cause Go panic/runtime error #16

Closed troyengel closed 3 years ago

troyengel commented 4 years ago

It appears specifying -i 1m or -i 2m falls outside an internal code/index range, but once you get to -i 3m it starts to work correctly (graceful failure for no data available). I use pikaur as my AUR helper, that's what the name of that directory in the build path output is from seen below.

$ pacman -Q stonks
stonks 1.0.8-1

1m

$ stonks -i 1m AAPL
panic: runtime error: index out of range [80] with length 80

goroutine 1 [running]:
github.com/ericm/stonks/graph.GenerateGraph(0xc00046b500, 0x50, 0xc, 0x1, 0x0, 0x0, 0x203000, 0xc00046b500)
    /home/tengel/.cache/pikaur/build/stonks/src/stonks/graph/graph.go:105 +0x1f0d
main.main.func1(0xc0000dcb00, 0xc00009bc50, 0x1, 0x3)
    /home/tengel/.cache/pikaur/build/stonks/src/stonks/main.go:167 +0x259
github.com/spf13/cobra.(*Command).execute(0xc0000dcb00, 0xc0000b6010, 0x3, 0x3, 0xc0000dcb00, 0xc0000b6010)
    /home/tengel/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:846 +0x29d
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000dcb00, 0xc0000aebc1, 0x911422, 0x5)
    /home/tengel/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
    /home/tengel/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
main.main()
    /home/tengel/.cache/pikaur/build/stonks/src/stonks/main.go:184 +0x7b7

2m

$ stonks -i 2m AAPL
panic: runtime error: index out of range [80] with length 80

goroutine 1 [running]:
github.com/ericm/stonks/graph.GenerateGraph(0xc0003e01c0, 0x50, 0xc, 0x1, 0x0, 0x0, 0x203000, 0xc0003e01c0)
    /home/tengel/.cache/pikaur/build/stonks/src/stonks/graph/graph.go:105 +0x1f0d
main.main.func1(0xc0000dcb00, 0xc00009bc50, 0x1, 0x3)
    /home/tengel/.cache/pikaur/build/stonks/src/stonks/main.go:167 +0x259
github.com/spf13/cobra.(*Command).execute(0xc0000dcb00, 0xc0000b6010, 0x3, 0x3, 0xc0000dcb00, 0xc0000b6010)
    /home/tengel/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:846 +0x29d
github.com/spf13/cobra.(*Command).ExecuteC(0xc0000dcb00, 0xc0000aebc1, 0x911422, 0x5)
    /home/tengel/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
    /home/tengel/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
main.main()
    /home/tengel/.cache/pikaur/build/stonks/src/stonks/main.go:184 +0x7b7

3m

$ stonks -i 3m AAPL
No bars were found for this time period for AAPL

My stonks was compiled about a week or so ago, no edits to the PKGBUILD made.

ericm commented 4 years ago

Are you still experiencing this issue?

troyengel commented 4 years ago

Hi, ... yes? We're still on the same version as when reported (1.0.8) -- would this be fixed by recompiling, is it a bug in one of the Go dependencies pulled down during build? Use a little trial and error:

1) 1m and 2m cause a crash as per above 2) Any range I tried not listed in this code returns "no chart for this time period": https://github.com/piquette/finance-go/blob/master/datetime/datetime.go

$ stonks -i 45m AAPL
No bars were found for this time period for AAPL

I suspect the out of range is due to that, as it is slurped in, passed to GetChart() to make the object and the object passed to GenerateChart() assuming that the interval is correct. So it would seem that perhaps it's because finance-go/datetime has problems handling anything other than what's listed in their code, and maybe 1m/2m are broken? (not a programmer :) )