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