[Tile-serving] [openstreetmap/osm2pgsql] Provide a stack trace on a lua error with flex backend (#1136)
mmd
notifications at github.com
Mon Apr 27 16:11:53 UTC 2020
Quick and dirty test:
```
diff --git a/src/output-flex.cpp b/src/output-flex.cpp
index 3ac29fe..44bc5fe 100644
--- a/src/output-flex.cpp
+++ b/src/output-flex.cpp
@@ -983,6 +983,32 @@ void output_flex_t::add_row(table_connection_t *table_connection,
}
}
+static int msghandler (lua_State *L) {
+ const char *msg = lua_tostring(L, 1);
+ if (msg == NULL) { /* is error object not a string? */
+ if (luaL_callmeta(L, 1, "__tostring") && /* does it have a metamethod */
+ lua_type(L, -1) == LUA_TSTRING) /* that produces a string? */
+ return 1; /* that is the message */
+ else
+ msg = lua_pushfstring(L, "(error object is a %s value)",
+ luaL_typename(L, 1));
+ }
+ luaL_traceback(L, L, msg, 1); /* append a standard traceback */
+ return 1; /* return the traceback */
+}
+
+static int docall (lua_State *L, int narg, int nres) {
+ int status;
+ int base = lua_gettop(L) - narg; /* function index */
+ lua_pushcfunction(L, msghandler); /* push message handler */
+ lua_insert(L, base); /* put it under function and args */
+ status = lua_pcall(L, narg, nres, base);
+ lua_remove(L, base); /* remove message handler from the stack */
+ return status;
+}
+
+
+
void output_flex_t::call_process_function(int index,
osmium::OSMObject const &object)
{
@@ -996,7 +1022,7 @@ void output_flex_t::call_process_function(int index,
get_options()->extra_attributes); // the single argument
luaX_set_context(lua_state(), this);
- if (lua_pcall(lua_state(), 1, 0, 0)) {
+ if (docall(lua_state(), 1, 0)) {
throw std::runtime_error{"Failed to execute lua processing function:"
" {}"_format(lua_tostring(lua_state(), -1))};
}
```
Returns:
```
Setting up table: planet_osm_rels
Using projection SRS 3857 (Spherical Mercator)
Reading in file: r1377803.osm
Using XML parser.
node cache: stored: 117(100.00%), storage efficiency: 1.39% (dense blocks: 1, sparse nodes: 116), hit rate: 100.00%
Osm2pgsql failed due to ERROR: Failed to execute lua processing function: /home/user/osm2pgsql/flex-config/compatible.lua:569: Error in 'add_row': Trying to add relation to table 'planet_osm_line'
stack traceback:
[C]: in function 'add_row'
/home/user/osm2pgsql/flex-config/compatible.lua:569: in function </home/user/osm2pgsql/flex-config/compatible.lua:534>
```
--
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/issues/1136#issuecomment-620083990
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/tile-serving/attachments/20200427/9d1444c8/attachment.htm>
More information about the Tile-serving
mailing list