GithubHelp home page GithubHelp logo

Crashed after executing the command about usql HOT 10 OPEN

spance avatar spance commented on September 24, 2024
Crashed after executing the command

from usql.

Comments (10)

spance avatar spance commented on September 24, 2024 1

I tried many times and finally found the problem.
My config file $HOME/.config/usql/config.yaml like this:

connections:
  xxx: xxxx
init: |
  \echo date `date`

Then after deleting the init fragment, no errors were reported.

from usql.

nineinchnick avatar nineinchnick commented on September 24, 2024 1

Oh I totally forgot there's a yaml config too, thanks! @kenshaw PTAL, \echo date date`` works with a regular .usqlrc.

from usql.

kenshaw avatar kenshaw commented on September 24, 2024 1

I'll look in to this shortly. Probably a simple oversight on my part.

from usql.

nineinchnick avatar nineinchnick commented on September 24, 2024

What's in your $HOME/.usqlrc? What's usql_static - how did you build it?

from usql.

spance avatar spance commented on September 24, 2024

The .usqlrc is an empty file, and the usql_static was downloaded from https://github.com/xo/usql/releases/download/v0.19.1/usql_static-0.19.1-linux-amd64.tar.bz2

from usql.

nineinchnick avatar nineinchnick commented on September 24, 2024

Are you sure it's empty? It fails when executing an \echo command, I wonder how it's being triggered and what are the arguments to it. Can you try running it with -X? This disables reading any init files.

from usql.

kenshaw avatar kenshaw commented on September 24, 2024

I'm not able to reproduce this error:

ken@ken-desktop:~/Downloads$ mkdir usql
ken@ken-desktop:~/Downloads$ cd usql/
[config.yaml.txt](https://github.com/xo/usql/files/15292979/config.yaml.txt)
ken@ken-desktop:~/Downloads/usql$ mv ../usql_static-0.19.1-linux-amd64.tar.bz2 .
ken@ken-desktop:~/Downloads/usql$ tar -jxvf usql_static-0.19.1-linux-amd64.tar.bz2 
usql_static
LICENSE
ken@ken-desktop:~/Downloads/usql$ md5sum usql_static
c110e337bb43dd359c34813bb459366c  usql_static
ken@ken-desktop:~/Downloads/usql$ ./usql_static 
Type "help" for help.

date Mon May 13 05:18:34 PM WIB 2024
(not connected)=> \q
ken@ken-desktop:~/Downloads/usql$ cat ~/.config/usql/config.yaml 
---
init: |
  \echo date `date`
ken@ken-desktop:~/Downloads/usql$ ./usql_static -V
usql 0.19.1
ken@ken-desktop:~/Downloads/usql$ 

Can you please share your exact yaml config file? Note that GitHub doesn't seem to allow uploads of .yaml extensions, for whatever reason. You'll need to rename the file prior to upload.

This is the simple debugging config file that I used:
config.txt

from usql.

kenshaw avatar kenshaw commented on September 24, 2024

Are you perhaps using something like Windows encoding? With \r\n line endings? I've tried all manner of variations and I can't cause that same block of code to escape under any input that I could come up with. I'm sure my code is bad, but it's going to be difficult to figure out the cause of this without the exact character sequence/input.

Are you able to get \echo to work in the init: stanza in a simpler form? For example:

init: '\echo hi'

Which has this output on my system:

$ usql
Type "help" for help.

hi
(not connected)=> \q

from usql.

spance avatar spance commented on September 24, 2024

I repeat it again.

~$ cat .config/usql/config.yaml
connections:
  xx: mysql://xxxx
  cr: mysql://xxxx
init: |
  \echo `date`

~$ ./usql
Type "help" for help.

panic: runtime error: slice bounds out of range [:43] with capacity 32

goroutine 1 [running]:
github.com/xo/usql/stmt.(*Params).Get(0xc000d0f660, 0xc00173ea28)
        github.com/xo/usql/stmt/params.go:86 +0x9fb
github.com/xo/usql/metacmd.(*Params).Get(0xc00174ef00, 0x1)
        github.com/xo/usql/metacmd/types.go:164 +0x192
github.com/xo/usql/metacmd.(*Params).GetOptional(0xc0007763c0?, 0xa0?)
        github.com/xo/usql/metacmd/types.go:189 +0x13
github.com/xo/usql/metacmd.init.0.func15(0xc00174ef00)
        github.com/xo/usql/metacmd/cmds.go:428 +0x2c
github.com/xo/usql/handler.(*Handler).Run.Decode.func3({0x6c8a398, 0xc0015fa9c0})
        github.com/xo/usql/metacmd/metacmd.go:26 +0xd8
github.com/xo/usql/metacmd.RunnerFunc.Run(0x56b4360?, {0x6c8a398?, 0xc0015fa9c0?})
        github.com/xo/usql/metacmd/types.go:82 +0x4d
github.com/xo/usql/handler.(*Handler).Run(0xc0015fa9c0)
        github.com/xo/usql/handler/handler.go:282 +0xb30
main.Run({0x6c2d9c0, 0xabad740}, 0xc001277cb0, 0xc000f22bd0, {0xc000f0cd40, 0xd})
        github.com/xo/usql/run.go:355 +0xce2
main.New.func3(0xc00012d808?, {0xabad740?, 0x7?, 0x5ed2453?})
        github.com/xo/usql/run.go:126 +0x185
github.com/spf13/cobra.(*Command).execute(0xc00012d808, {0xc0000740a0, 0x0, 0x0})
        github.com/spf13/[email protected]/command.go:983 +0xaca
github.com/spf13/cobra.(*Command).ExecuteC(0xc00012d808)
        github.com/spf13/[email protected]/command.go:1115 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/[email protected]/command.go:1039
github.com/spf13/cobra.(*Command).ExecuteContext(0xc0000740a0?, {0x6c2d9c0?, 0xabad740?})
        github.com/spf13/[email protected]/command.go:1032 +0x47
main.main()
        github.com/xo/usql/main.go:40 +0x13c
~$
~$ vim .config/usql/config.yaml
~$ cat .config/usql/config.yaml
connections:
  xx: mysql://xxxx
  cr: mysql://xxxx

~$
~$ ./usql
Type "help" for help.

(not connected)=> \q
~$

from usql.

spance avatar spance commented on September 24, 2024

Now I found the cause of this problem, because the output of the date command contains some unicode characters (non-ascii), causing the variable i calculation in the Params.Get() method to become longer.
There is my simple fix:

i = start + len([]rune(z)) - 1   // Line-59

Another solution: utf8.RuneCountInString(z)

from usql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.