{"action":"closed","issue":{"number":92,"created_at":"2011-09-20T20:41:14Z","pull_request":{"diff_url":null,"patch_url":null,"html_url":null},"body":"Current drafts of the Redis scripting branch represent errors as `{err = MESSAGE}`. Considering that there are very few situations where an error is *expected* to be returned from Redis, directly raising a Lua error would in most cases be a better solution. Reasons for this include:\r\n\r\n* Circumstances in which Redis returns error replies (unsupported operations on a data type, using the wrong number or type of arguments to a command, overflowing integers and strings, and protocol syntax errors) are remarkably similar to situations in which Lua's standard libraries raise errors.\r\n* In most cases, a Redis error represents something that would cause the rest of the script to fail regardless. Since there are few conditions where an error reply is to be *expected*, it makes more sense to bail out by default and allow the programmer to suppress the error when it *is* expected with `pcall`.\r\n* The original stated motivation for the current error format was \"[Y]ou should be able to call a Redis command without even caring about what he returned, save the reply into a var, and return it later as the user directly called Redis.\" Redis errors occur too rarely for this to be a common use case, and at any rate raising a Lua error will return the fact that an error occurred to the user immediately.\r\n* Related to the above, Redis scripting is expected to be mainly used for creating commands that manipulate or at least introspect data. If a person is expecting a multi-bulk reply, receives an error, but does not check to see whether or not it is an error, he could return confusing data to the user or make misguided modifications to the database.\r\n\r\nThat said, the `{err = MESSAGE}` representation could be useful if an error was returned as a multi-bulk reply. (It would be relatively simple to special-case this in the code that translates Redis responses to Lua types.) But in most cases it makes more sense to have Redis errors map directly to Lua errors.","comments":3,"title":"Suboptimal Lua representation of Redis errors","updated_at":"2011-10-20T14:06:24Z","url":"https://api.github.com/repos/antirez/redis/issues/92","id":1691502,"assignee":null,"milestone":null,"closed_at":"2011-10-20T14:06:24Z","user":{"avatar_url":"https://secure.gravatar.com/avatar/ba15b77e94a0771babd7e3801403b9a8?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"ba15b77e94a0771babd7e3801403b9a8","url":"https://api.github.com/users/leafstorm","id":271305,"login":"leafstorm"},"html_url":"https://github.com/antirez/redis/issues/92","labels":[],"state":"closed"},"legacy":{"number":92,"action":"closed","issue":1691502}}