This function is used in order to push an error on the Lua stack in the * format used by redis.pcall to return errors, which is a lua table * with a single "err" field set to the error string. Note that this * table is never a valid reply by proper commands, since the returned * tables are otherwise always indexed by integers, never by strings. */
| 284 | * table is never a valid reply by proper commands, since the returned |
| 285 | * tables are otherwise always indexed by integers, never by strings. */ |
| 286 | void luaPushError(lua_State *lua, char *error) { |
| 287 | lua_Debug dbg; |
| 288 | |
| 289 | /* If debugging is active and in step mode, log errors resulting from |
| 290 | * Redis commands. */ |
| 291 | if (ldb.active && ldb.step) { |
| 292 | ldbLog(sdscatprintf(sdsempty(),"<error> %s",error)); |
| 293 | } |
| 294 | |
| 295 | lua_newtable(lua); |
| 296 | lua_pushstring(lua,"err"); |
| 297 | |
| 298 | /* Attempt to figure out where this function was called, if possible */ |
| 299 | if(lua_getstack(lua, 1, &dbg) && lua_getinfo(lua, "nSl", &dbg)) { |
| 300 | sds msg = sdscatprintf(sdsempty(), "%s: %d: %s", |
| 301 | dbg.source, dbg.currentline, error); |
| 302 | lua_pushstring(lua, msg); |
| 303 | sdsfree(msg); |
| 304 | } else { |
| 305 | lua_pushstring(lua, error); |
| 306 | } |
| 307 | lua_settable(lua,-3); |
| 308 | } |
| 309 | |
| 310 | /* In case the error set into the Lua stack by luaPushError() was generated |
| 311 | * by the non-error-trapping version of redis.pcall(), which is redis.call(), |
no test coverage detected