Types of Failures
An error raised in Lua code generally halts execution and outputs a message describing what happened and where. This type of erroring is good for things that can and should be fixed by the programmer. Generally, if a user sees this kind of error, you would want them to submit a bug report.
Many functions, especially when dealing with socket programming, can fail without there actually being a problem with the application. For example, when connecting to a remote host that is currently turned off, you would usually rather try again with a different host or eloquently tell the user what happened.
Calling a ratchet function within
In the case of "hard" errors, those thrown by Lua internally or errors indicating programmer error, the error will be a string value describing the error. It is generally best to let the errors propogate so they can be noticed and dealt with.
In the case of "soft" errors, such as a socket call timing out or a connection
being refused, the error will be a table object with a set of attributes and
methods providing information about what happened. The most useful decision
making attribute is the error code or name, which will usually match up with
To check for this code, the error object has a method
local success, err = pcall(socket.connect, socket) if not success then if ratchet.error.is(err, "ETIMEDOUT") then logger.warning("Connection to host timed out: "..host) return false elseif ratchet.error.is(err, "ECONNREFUSED") then logger.warning("Connection to host refused: "..host) return false else error(err) end end
See the man pages for the socket system call you're using for details on exactly what errors it can fail with.
See the API documentation