[Tile-serving] [openstreetmap/osm2pgsql] Provide a stack trace on a lua error with flex backend (#1142)

Jochen Topf notifications at github.com
Fri May 1 07:58:47 UTC 2020


@joto requested changes on this pull request.

This looks better now. I added some small nit-pick comments. I'd probably put this function into the `lua-utils.cpp` file and not made it a member of `output_flex_t`, because it isn't really related to it, it is just a Lua helper function.

> +        }
+        else {
+            msg = lua_pushfstring(lua_state, "(error object is a %s value)",
+                                  luaL_typename(lua_state, 1));
+        }
+    }
+    luaL_traceback(lua_state, lua_state, msg, 1); // append a standard traceback
+    return 1;                                     // return the traceback
+}
+
+int output_flex_t::do_pcall(int narg, int nres)
+{
+    int const base = lua_gettop(lua_state()) - narg; // function index
+    lua_pushcfunction(lua_state(), msghandler);      // push message handler
+    lua_insert(lua_state(), base);                   // put it under function and args
+    int status = lua_pcall(lua_state(), narg, nres, base);

Can be `const`

> @@ -983,6 +983,35 @@ void output_flex_t::add_row(table_connection_t *table_connection,
     }
 }
 
+static int msghandler(lua_State *lua_state)
+{
+    assert(lua_state);
+
+    char const *msg = lua_tostring(lua_state, 1);
+    if (msg == nullptr) {                                // is error object not a string?
+        if (luaL_callmeta(lua_state, 1, "__tostring") && // does it have a metamethod
+            lua_type(lua_state, -1) == LUA_TSTRING) {    // that produces a string?
+            return 1;                                    // that is the message
+        }
+        else {

Formatting looks unusual. Did you run `clang-format`?

> @@ -983,6 +983,35 @@ void output_flex_t::add_row(table_connection_t *table_connection,
     }
 }
 
+static int msghandler(lua_State *lua_state)

Maybe a bit more descriptive function name?

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/osm2pgsql/pull/1142#pullrequestreview-404056955
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20200501/8569bec2/attachment.htm>


More information about the Tile-serving mailing list