neovim / go-client

Nvim Go client
https://pkg.go.dev/github.com/neovim/go-client
Apache License 2.0
561 stars 37 forks source link

ExecLua panic on result decoding #155

Closed kndndrj closed 1 year ago

kndndrj commented 1 year ago

Hi,

I'm not sure if I'm doing something wrong or is it a bug, but I can't get ExecLua to work.

My observation is that if you pass in the wrong type of variable (e.g. lua returns table, you pass in string), you only get an error, but it doesn't panic. But if the types match (lua returns string, you pass in string) then the code panics. I tried a bunch of pointer/no pointer, slice/slice pointer combinations with lua code with return and without.

Any help would be appreciated. Thanks.

A few examples:

var err error

// panics
var res string
err = v.ExecLua(`
    function fn()
      return "hi"
    end
    return fn()
`, &res)

// panics
err = v.ExecLua(`
    function fn()
      return "hi"
    end
    fn()
`, nil)

// panics
resSlice := make([]string, 1)
err = v.ExecLua(`
    function fn()
      return {"hi"}
    end
    return fn()
`, resSlice)

// doesn't panic
// err: msgpack: cannot convert ArrayLen to string
var res2 string
err = v.ExecLua(`
    function fn()
      return {"hi"}
    end
    return fn()
`, &res2)

This is the panic:

panic: runtime error: invalid memory address or nil pointer dereference
 signal SIGSEGV: segmentation violation code=
0x2 addr=0x18 pc=0x104c50f58

goroutine 55 running:
 main.main.func2.3(0x140006117e8?
 {0x140000a80d0
 0x1
 0x1?})
 /Users/andrej/Repos/ndb/db
ee/main.go:103 +0x398

reflect.Value.call(
{0x104e84500?
 0x1400000c5e8?
 0x13?}

 {0x104c51d2a
 0x4}
 {0x1400007b7a0
 0x2
 0x2?
})
 /opt/homebrew/Cellar/go/1.20.4/libexec/src/reflect/value.go:586 +0x87c
 reflect.Value.Call(
{0x104e84500?
 0x1400000c5e8?
 0x0?}
 {0x1400007b7a0?

 0x0?
 0x0?})
 /opt/homebrew/Cellar/go/1.20.4/libexec/src/reflect/value.go:370 +
0x90

github.com/neovim/go-client/msgpack/rpc.(*Endpoint).handleRequest.func1()
 /Users/andrej/go/pkg/mod/github.com/neovi
m/go-client@v1.2.1/msgpack/rpc/rpc.go:550
 +0x48

created by github.com/neovim/go-client/msgpack/rpc.(*Endpoint).handleRequest
 /Users/andrej/go/pkg/mod/github.com/ne
ovim/go-client@v1.2.1/msgpack/rpc/rpc.go:549 +
0x324
zchee commented 1 year ago

@kndndrj Thanks for the post issue. I'll debug it.

justinmk commented 1 year ago

are you missing --embed ? see https://github.com/neovim/go-client/pull/161