sheepla / strans

📖 A command line translate tool with interactive mode inspired by translate-shell
MIT License
34 stars 0 forks source link

Error `404 Not Found` `panic: runtime error: invalid memory address or nil pointer dereference` #9

Closed sheepla closed 1 year ago

sheepla commented 1 year ago

Translation may fail with a 404 error if the source text contains / symbol(s):

[auto -> en]
> こんにちは/世界
an error occurred on executing HTTP method: https://lingva.ml/api/v1/auto/en/%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF/%E4%B8%96%E7%95%8C 404 Not Found
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x0 pc=0xb00467]

goroutine 1 [running]:
github.com/sheepla/strans/repl.Start(0xc000027140, 0x0)
        C:/Users/admin/ghq/github.com/sheepla/strans/repl/repl.go:78 +0x487
main.run(0xc000026540)
        C:/Users/admin/ghq/github.com/sheepla/strans/main.go:165 +0x471
github.com/urfave/cli/v2.(*Command).Run(0xc000002c80, 0xc000026540, {0xc000026080, 0x4, 0x4})
        C:/Users/admin/go/pkg/mod/github.com/urfave/cli/v2@v2.23.7/command.go:271 +0xa42
github.com/urfave/cli/v2.(*App).RunContext(0xc000108000, {0xcc32d0?, 0xc00000e0d8}, {0xc000026080, 0x4, 0x4})
        C:/Users/admin/go/pkg/mod/github.com/urfave/cli/v2@v2.23.7/app.go:333 +0x665
github.com/urfave/cli/v2.(*App).Run(...)
        C:/Users/admin/go/pkg/mod/github.com/urfave/cli/v2@v2.23.7/app.go:310
main.main()
        C:/Users/admin/ghq/github.com/sheepla/strans/main.go:38 +0x45
sheepla commented 1 year ago

It probably didn't percent-encode the string properly when constructing the URL.

sheepla commented 1 year ago

It seems to need to encode the URL parameter before joining the paths with path.Join(). I will fix.