bensadeh / circumflex

🌿 It's Hacker News in your terminal

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Got an issue when run go run main.go

infinitylx opened this issue · comments

When trying to run go run main.go got this:

    panic: runtime error: slice bounds out of range [:28] with capacity 0

goroutine 1 [running]:
code.rocketnine.space/tslocum/cview.(*Application).HandlePanic(0xc000979e00)
    /Users/user123/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.7/application.go:142 +0x85
panic({0x1801380, 0xc0001432a8})
    /usr/local/Cellar/go/1.17.2/libexec/src/runtime/panic.go:1038 +0x215
clx/handler.getOnlineStories(0xc000b69b78, 0x17440f3, 0x1c, 0xc5, 0x3e, 0xc00095f680, 0xc0004df800)
    /Users/user123/svalko/circumflex/handler/handler.go:88 +0x28a
clx/handler.(*StoryHandler).GetStories(0xc0000244c0, 0xc000523780, 0xc000980a40, 0x1167501, 0x0, 0x9c)
    /Users/user123/svalko/circumflex/handler/handler.go:48 +0x79
clx/model.SetAfterInitializationAndAfterResizeFunctions.func1(0x116a210, 0xc000b69cb0)
    /Users/user123/svalko/circumflex/model/model.go:42 +0xe5
code.rocketnine.space/tslocum/cview.(*Application).Run.func2({0x17b75a0, 0xc00075c000})
    /Users/user123/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.7/application.go:426 +0x2ea
code.rocketnine.space/tslocum/cview.(*Application).Run(0xc000979e00)
    /Users/user123/go/pkg/mod/code.rocketnine.space/tslocum/cview@v1.5.7/application.go:481 +0x34a
clx/clx.Run(0xc00095f050)
    /Users/user123/svalko/circumflex/clx/clx.go:21 +0xb2
clx/cmd.Root.func1(0xc0009a0280, {0x1849cc8, 0x0, 0x0})
    /Users/user123/svalko/circumflex/cmd/root.go:34 +0xaa
github.com/spf13/cobra.(*Command).execute(0xc0009a0280, {0xc000020200, 0x0, 0x0})
    /Users/user123/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:860 +0x5f8
github.com/spf13/cobra.(*Command).ExecuteC(0xc0009a0280)
    /Users/user123/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:974 +0x3bc
github.com/spf13/cobra.(*Command).Execute(...)
    /Users/user123/go/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:902
main.main()
    /Users/user123/svalko/circumflex/main.go:9 +0x1e
exit status 2

My environment is:

>git status
HEAD detached at 1.27
nothing to commit, working tree clean

>go version
go version go1.17.2 darwin/amd64

Hi Wladislaw, thanks for posting this issue and letting me know about the panic.

It looks like there was an issue in getting the screen height of your terminal. What terminal are you currently using?

Would you be able to try running go run main.go from Alacritty? It would help me understand if it is a terminal-specific bug or something else.

Hi, no problem.

My terminal is iTerm2 Build 3.4.12.
Also tried to run go run main.go in macOS terminal and Kitty Build 3.4.12 and got the same issue.

Recent macOS can't verify Alacritty so I'm unable to use it...

Ah, thanks for checking different terminals, I don't think you need to test in Alacritty as well 😊

The underlying command is for providing screen size is stty size, can you run this command from your terminal and report if you get the dimensions of your terminal?

Also, could you say a bit more when this panic occurs? Is it right after running go run main.go, or is after using clx for a while?

Sorry for the confusion, but I think I identified the bug. (It had nothing to do with getting the dimensions of the terminal).

It seems that the endpoint clx is consuming in some instances returns empty JSONs.

I need look a bit more into the different ways to tackle this issue, but I should have enough information to be able to implement a fix.

Hi again,

I’ve looked at the option to use different endpoints along with their pros and cons. The current endpoint I am using has so far worked great: it is very fast and simple to use. The downside to using it is that I don’t control the endpoint myself and cannot debug it if it suddenly returns empty results, like I suspect was in your case. Another benefit to using this endpoint is that the result is very similar to what you will find https://news.ycombinator.com/ directly.

The official Hacker News API is more complex because you have to first get a list of IDs, and then send a request for each of these IDs. I tried to use this endpoint instead, but the result was that clx became around 8x slower which wasn’t a great user experience. If your issue becomes more prevalent in the future, perhaps an option to toggle between the endpoint would be a solution. However, the use of these endpoint is different enough that this would add a lot more complexity to the application.

I also looked at Algolia’s API: they are more similar to cheeaun's unofficial Hacker News API (fast and simple), but the order of the submissions was less accurate and did not reflect https://news.ycombinator.com/. It is true that either The official Hacker News API or Algolia's API would be an improvement compared to no results at all. However, supporting different APIs simultaneously adds a lot of complexity and refactoring which would take some time to implement properly.

Sorry again that you’re not able to use clx. Currently, cheeaun's unofficial Hacker News API is the fastest, simplest and most accurate endpoint which has been the easiest to implement. I can't promise any changes to this in the short term, but I will keep an eye out for feedback on this topic to see if support for different endpoints should be implemented at some point in the future.

I have made some changes to the endpoints. Could you try again on 48df798 in the dev branch?

Should be

git checkout 48df798
go run main.go

The changes are available in 1.29, hope this solves the issues for you, if not feel free to re-open this ticket.

I have this issue after installing today. It worked a few seconds then this happened. possibly after a resize of the window.

panic: runtime error: slice bounds out of range [:37] with capacity 0

goroutine 66 [running]:
clx/hn/services/hybrid.(*Service).FetchItems(0x0?, 0x24, 0x0?)
	/home/runner/work/circumflex/circumflex/hn/services/hybrid/hybrid.go:30 +0x4ac
clx/bubble/list.(*Model).FetchFrontPageStories.func1()
	/home/runner/work/circumflex/circumflex/bubble/list/list.go:114 +0x88
github.com/charmbracelet/bubbletea.(*Program).StartReturningModel.func6.1()
	/home/runner/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.22.1/tea.go:469 +0x38
created by github.com/charmbracelet/bubbletea.(*Program).StartReturningModel.func6
	/home/runner/go/pkg/mod/github.com/charmbracelet/bubbletea@v0.22.1/tea.go:467 +0x11c
❯ stty size
40 127