MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / luaPushError

Function luaPushError

src/scripting.cpp:289–311  ·  view source on GitHub ↗

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. */

Source from the content-addressed store, hash-verified

287 * table is never a valid reply by proper commands, since the returned
288 * tables are otherwise always indexed by integers, never by strings. */
289void 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(),

Callers 2

luaRedisGenericCommandFunction · 0.85

Calls 8

ldbLogFunction · 0.85
sdscatprintfFunction · 0.85
sdsemptyFunction · 0.85
lua_pushstringFunction · 0.85
lua_getstackFunction · 0.85
lua_getinfoFunction · 0.85
sdsfreeFunction · 0.85
lua_settableFunction · 0.85

Tested by

no test coverage detected