mike182uk / snpt

A gist powered CLI snippet retriever

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Return lots of `Failed to retrieve gist file content from: `

scillidan opened this issue · comments

Hi, dude. 👋

Is snpt has some way to debug?

I try the 3.0.0 version ,and build snpt.exe from source. After snpt token, I run snpt sync . I successfully synchronized a gist.

image

And I ping gist.githubusercontent.com:

正在 Ping gist.githubusercontent.com [185.199.108.133] 具有 32 字节的数据:
来自 185.199.108.133 的回复: 字节=32 时间=182ms TTL=50
来自 185.199.108.133 的回复: 字节=32 时间=184ms TTL=50
来自 185.199.108.133 的回复: 字节=32 时间=183ms TTL=50
来自 185.199.108.133 的回复: 字节=32 时间=181ms TTL=50

185.199.108.133 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 181ms,最长 = 184ms,平均 = 182ms
    ```

Hey

Weird that it sync'd one and not the rest 🤔

The error is thrown here

You could maybe try tweaking this logic here to try and see what the error is?

i.e

return "", fmt.Errorf("Failed to retrieve gist file content from: %s (%d)", url, res.StatusCode)

or print the contents of errs?

Sorry for that I'm very new to golang. I don't sure if I can understand what you mean.
I modified this line to ..., url, res.StatusCode) and re-make build.
But returned the same result.

And the is the log of Tabby Terminal:

set FLASK_APP=runserver.py;57Hync;56Hsync;57Hnsync;58Hpsync;59Htsync;60H sync;61H
�]0;C:\Windows\SYSTEM32\cmd.exe - snpt  sync�Gists last synced 20 hours ago
⠋ Syncing gists... �
...
⠼ Syncing gists... ;18H
...
Failed to retrieve gist file content from: https://gist.githubusercontent.com/scillidan/907f166f2ab6f726d32443147896de1�
c/raw/6abf7d00b743b7e20477cbcb091eedfca783c807/convert.py
...
⠙ Syncing gists... ug-0.log
...
is ;2;255;135;0mpkg v5.0.2 via nodejs v18.15.0 took 3m3s
home\webtorrent-hybrid-5.0.2\webtorrent-hybrid-5.0.2 λ snpt sync
Gists last synced 20 hours ago
Failed to retrieve gist file content from: https://gist.githubusercontent.co
m/scillidan/907f166f2ab6f726d32443147896de1c/raw/6abf7d00b743b7e20477cbcb091
eedfca783c807/convert.py
...
Failed to retrieve gist file content from: https://gist.githubusercontent.co�
m/scillidan/9aebe2d387a1c4e0879bcf93417fa8fd/raw/a78a1cfb0987aed4b6a3a1c7464�
88b2195480081/excalith-start-page.json
...
Failed to retrieve gist file content from: https://gist.githubusercontent.co�
m/scillidan/78a8ed830b7bc2f6e209b462fab3bab0/raw/97d101448b47a595993ba55d9e0�
bd5091128145f/summer_triangle.json
0 gist(s) synced
�]0;C:\Windows\SYSTEM32\cmd.exe�

The file was very long. I left the content with changes.

Hey

So you would need to swap

return "", fmt.Errorf("Failed to retrieve gist file content from: %s", url)

to

return "", fmt.Errorf("Failed to retrieve gist file content from: %s (%d)", url, res.StatusCode)

and run make build

Then when an error occurs it will look like

Failed to retrieve gist file content from: https://gist.githubusercontent.com/... (200)

(200) is the status code, it should provide an indication if the error is related to auth etc.

Alternatively you can opt to just print errs using fmt.Println(errs)

So something like:

fmt.Println(errs)
return "", fmt.Errorf("Failed to retrieve gist file content from: %s", url)

Thanks for your guidance, dude.
I ran it for many times. One of them, it successed. It's o weird.

image

image

I tried snpt on Termux in same network. It works very well.
Here should are some strange problems on my PC's network. So not about snpt.

Huh that is weird

Just to be clear, RetrieveGistFileContent looks like this with your debugging changes right:

// RetrieveGistFileContent retrieves the contents of a file associated with a Gist
func (r *Retriever) RetrieveGistFileContent(file *github.GistFile) (string, error) {
	url := *file.RawURL

	res, content, errs := r.httpClient.Get(url).End()

	if errs != nil || res.StatusCode != 200 {
		fmt.Println(errs)
		return "", fmt.Errorf("Failed to retrieve gist file content from: %s (%d)", url, res.StatusCode)
	}

	return content, nil
}

Also noticed your building on go v1.21.5 - Whilst it should be fine, go v1.20.0 is what is listed in go.mod, are you able to downgrade and try building on this version?

You are right. I forgot add fmt.Println(errs) before.
I also forgot to mention that I need to use VPN to access github.com and gist.githubusercontent.com, and I can ping them.
I installed go v1.20.0. When I run snpt sync, it return:

Gists last synced 6 minutes ago
⠏ Syncing gists...[Get "https://gist.githubusercontent.com/scillidan/658474f6a77c3305054a5a1a0867ee74/raw/8a88e24616a4e1fa6ae70539ce679af66b937128/night_edit.theme": read tcp 192.168.31.239:49332->185.199.108.133:443: wsarecv: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.]
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x10 pc=0xbf059b]

goroutine 1 [running]:
github.com/mike182uk/snpt/internal/platform/gist.(*Retriever).RetrieveGistFileContent(0xccc3f7?, 0x0?)
        D:/binr/gist_snpt/internal/platform/gist/retriever.go:53 +0xdb
github.com/mike182uk/snpt/cmd/snpt/command/sync.New.func1(0xc0001a6c00?, {0xcc7744?, 0x0?, 0x0?})
        D:/binr/gist_snpt/cmd/snpt/command/sync/sync.go:71 +0x679
github.com/spf13/cobra.(*Command).execute(0xc0001a6c00, {0x10d4028, 0x0, 0x0})
        C:/Users/scillidan/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:983 +0xaaa
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001a6000)
        C:/Users/scillidan/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x425
github.com/spf13/cobra.(*Command).Execute(...)
        C:/Users/scillidan/go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
main.main()
        D:/binr/gist_snpt/cmd/snpt/snpt.go:87 +0x405

Ah, your behind a VPN, this is probably a timeout issue. Do any of the Gists sync, or do they all error out with this error? How many Gists are you trying to sync?

If you don't use a VPN, does it work as expected?

I can't visit github.com, gist.githubusercontent.com, if not with VPN. Through ping them, I can know that they have been redirected. And snpt sync can't work.

When I turn on VPN. I can visit and ping them. Through ping, I see that their ip addresses are correct. But snpt sync still not work at most most of the time.

I have successfully synchronized 1 gist and all gist on PC. But only once. After that, I deleted snpt.db and tried again. I can never get, again 🤡.

My PC is connected to the router through a cable, and my phone is under the router's wifi network. On my phone, I try snpt with VPN, and with the same mode Global. This mode forwards all network traffic. I add a gist for test, and it successed.

image

A few days ago, on PC, I ordered a new VPN subscription. And used the latest version client. The snpt works now!

image

Great stuff, glad you got it working 👍