luasocket / "object is not a string" issue

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

luasocket / "object is not a string" issue

Laurent FAILLIE
Hello,

I have the following code :

       local socket = require("socket")
       local clt = socket.try(socket.connect( "celeron.chez.moi", 7634 ))
       local try = socket.newtry(function() clt:close() end)
       local s, err = clt:receive('*a')
       clt:close()

And I'm testing it with Lua 5.1.5

It tried it on 2 machines with "similar" configuration.
On the first machine, is it working, but on a second one, I got a
    /usr/bin/lua: (error object is not a string)

As per http://www.luafaq.org/, it's due to 'error' handling.
Any idea how I can trouble shoot ?

Thanks

Laurent

PS: the fun part in a remote machine with the code is working, and is it
on the famous "celeron" when the code is failing.


Reply | Threaded
Open this post in threaded view
|

Re: luasocket / "object is not a string" issue

Matthew Wild
On 6 April 2013 17:35, Laurent Faillie <[hidden email]> wrote:

> Hello,
>
> I have the following code :
>
>        local socket = require("socket")
>        local clt = socket.try(socket.connect( "celeron.chez.moi", 7634 ))
>        local try = socket.newtry(function() clt:close() end)
>        local s, err = clt:receive('*a')
>        clt:close()
>
> And I'm testing it with Lua 5.1.5
>
> It tried it on 2 machines with "similar" configuration.
> On the first machine, is it working, but on a second one, I got a
>     /usr/bin/lua: (error object is not a string)
>
> As per http://www.luafaq.org/, it's due to 'error' handling.
> Any idea how I can trouble shoot ?

socket.try() throws a table as an error, not a string (i.e. not an
error message). It's designed to be used with socket.protect().

These functions are primarily used inside LuaSocket itself. If you
want to throw a normal error when the connection fails, use assert():

        local socket = require("socket")
        local clt = assert(socket.connect( "celeron.chez.moi", 7634 ))
        local s, err = clt:receive('*a')
        clt:close()

If you are definitely sure you want to use socket.try() instead, read
the documentation on socket.newtry() and socket.protect() as well.

Regards,
Matthew

Reply | Threaded
Open this post in threaded view
|

Re: luasocket / "object is not a string" issue

Laurent FAILLIE
Hi Matthew,

> These functions are primarily used inside LuaSocket itself. If you want to
> throw a normal error when the connection fails, use assert()

Ha, ok : I got this code from the Internet but ok, without them, it's
working fine.
So, I got the error message and I found out the problem that was due to
a misconfiguration at server side.

Thanks

Laurent