Skip to content

Commit 439c6b1

Browse files
authored
Report OSM ID on Lua processing error (#535)
1 parent b360f40 commit 439c6b1

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

include/osm_lua_processing.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ class OsmLuaProcessing {
191191

192192
inline AttributeStore &getAttributeStore() { return attributeStore; }
193193

194+
struct luaProcessingException :std::exception {};
195+
194196
private:
195197
/// Internal: clear current cached state
196198
inline void reset() {
@@ -247,7 +249,6 @@ class OsmLuaProcessing {
247249

248250
std::deque<std::pair<OutputObjectRef, AttributeStoreRef>> outputs; ///< All output objects that have been created
249251
boost::container::flat_map<std::string, std::string> currentTags;
250-
251252
};
252253

253254
#endif //_OSM_LUA_PROCESSING_H

src/osm_lua_processing.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ bool supportsRemappingShapefiles = false;
1010

1111
int lua_error_handler(int errCode, const char *errMessage)
1212
{
13-
cerr << "lua runtime error: " << errMessage << endl;
14-
std::string traceback = (*g_luaState)["debug"]["traceback"];
15-
cerr << "traceback: " << traceback << endl;
16-
exit(0);
13+
std::cerr << "lua runtime error: " << std::endl;
14+
kaguya::util::traceBack(g_luaState->state(), errMessage); // full traceback on 5.2+
15+
kaguya::util::stackDump(g_luaState->state());
16+
throw OsmLuaProcessing::luaProcessingException();
1717
}
1818

1919
// ---- initialization routines
@@ -542,7 +542,12 @@ bool OsmLuaProcessing::scanRelation(WayID id, const tag_map_t &tags) {
542542
isWay = false;
543543
isRelation = true;
544544
currentTags = tags;
545-
luaState["relation_scan_function"](this);
545+
try {
546+
luaState["relation_scan_function"](this);
547+
} catch(luaProcessingException &e) {
548+
std::cerr << "Lua error on scanning relation " << originalOsmID << std::endl;
549+
exit(1);
550+
}
546551
if (!relationAccepted) return false;
547552

548553
osmStore.store_relation_tags(id, tags);
@@ -561,7 +566,12 @@ void OsmLuaProcessing::setNode(NodeID id, LatpLon node, const tag_map_t &tags) {
561566
currentTags = tags;
562567

563568
//Start Lua processing for node
564-
luaState["node_function"](this);
569+
try {
570+
luaState["node_function"](this);
571+
} catch(luaProcessingException &e) {
572+
std::cerr << "Lua error on node " << originalOsmID << std::endl;
573+
exit(1);
574+
}
565575

566576
if (!this->empty()) {
567577
TileCoordinates index = latpLon2index(node, this->config.baseZoom);
@@ -606,12 +616,15 @@ void OsmLuaProcessing::setWay(WayID wayId, LatpLonVec const &llVec, const tag_ma
606616

607617
bool ok = true;
608618
if (ok) {
609-
luaState.setErrorHandler(kaguya::ErrorHandler::throwDefaultError);
610-
611619
//Start Lua processing for way
612-
kaguya::LuaFunction way_function = luaState["way_function"];
613-
kaguya::LuaRef ret = way_function(this);
614-
assert(!ret);
620+
try {
621+
kaguya::LuaFunction way_function = luaState["way_function"];
622+
kaguya::LuaRef ret = way_function(this);
623+
assert(!ret);
624+
} catch(luaProcessingException &e) {
625+
std::cerr << "Lua error on way " << originalOsmID << std::endl;
626+
exit(1);
627+
}
615628
}
616629

617630
if (!this->empty()) {
@@ -691,7 +704,12 @@ void OsmLuaProcessing::setRelation(int64_t relationId, WayVec const &outerWayVec
691704

692705
// Start Lua processing for relation
693706
if (!isNativeMP && !supportsWritingRelations) return;
694-
luaState[isNativeMP ? "way_function" : "relation_function"](this);
707+
try {
708+
luaState[isNativeMP ? "way_function" : "relation_function"](this);
709+
} catch(luaProcessingException &e) {
710+
std::cerr << "Lua error on relation " << originalOsmID << std::endl;
711+
exit(1);
712+
}
695713
if (this->empty()) return;
696714

697715
// Assemble multipolygon

0 commit comments

Comments
 (0)