MCPcopy Create free account
hub / github.com/Tencent/Tendis / luaPushError

Function luaPushError

src/tendisplus/script/lua_state.cpp:151–172  ·  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

149 * table is never a valid reply by proper commands, since the returned
150 * tables are otherwise always indexed by integers, never by strings. */
151void luaPushError(lua_State* lua, const char* error) {
152 lua_Debug dbg;
153
154 // TODO(takenliu): lua debug
155 /* If debugging is active and in step mode, log errors resulting from
156 * Redis commands. */
157
158 lua_newtable(lua);
159 lua_pushstring(lua, "err");
160
161 /* Attempt to figure out where this function was called, if possible */
162 if (lua_getstack(lua, 1, &dbg) && lua_getinfo(lua, "nSl", &dbg)) {
163 std::string msg = std::string(dbg.source) + ": " +
164 std::to_string(dbg.currentline) + ": " + std::string(error);
165 LOG(INFO) << "luaPushError:" << msg;
166 lua_pushstring(lua, msg.c_str());
167 } else {
168 LOG(INFO) << "luaPushError:" << error;
169 lua_pushstring(lua, error);
170 }
171 lua_settable(lua, -3);
172}
173
174/* In case the error set into the Lua stack by luaPushError() was generated
175 * by the non-error-trapping version of redis.pcall(), which is redis.call(),

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected