Skip to content

Commit

Permalink
Report OSM ID on Lua processing error (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
systemed authored Sep 18, 2023
1 parent b360f40 commit 439c6b1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
3 changes: 2 additions & 1 deletion include/osm_lua_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ class OsmLuaProcessing {

inline AttributeStore &getAttributeStore() { return attributeStore; }

struct luaProcessingException :std::exception {};

private:
/// Internal: clear current cached state
inline void reset() {
Expand Down Expand Up @@ -247,7 +249,6 @@ class OsmLuaProcessing {

std::deque<std::pair<OutputObjectRef, AttributeStoreRef>> outputs; ///< All output objects that have been created
boost::container::flat_map<std::string, std::string> currentTags;

};

#endif //_OSM_LUA_PROCESSING_H
42 changes: 30 additions & 12 deletions src/osm_lua_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ bool supportsRemappingShapefiles = false;

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

// ---- initialization routines
Expand Down Expand Up @@ -542,7 +542,12 @@ bool OsmLuaProcessing::scanRelation(WayID id, const tag_map_t &tags) {
isWay = false;
isRelation = true;
currentTags = tags;
luaState["relation_scan_function"](this);
try {
luaState["relation_scan_function"](this);
} catch(luaProcessingException &e) {
std::cerr << "Lua error on scanning relation " << originalOsmID << std::endl;
exit(1);
}
if (!relationAccepted) return false;

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

//Start Lua processing for node
luaState["node_function"](this);
try {
luaState["node_function"](this);
} catch(luaProcessingException &e) {
std::cerr << "Lua error on node " << originalOsmID << std::endl;
exit(1);
}

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

bool ok = true;
if (ok) {
luaState.setErrorHandler(kaguya::ErrorHandler::throwDefaultError);

//Start Lua processing for way
kaguya::LuaFunction way_function = luaState["way_function"];
kaguya::LuaRef ret = way_function(this);
assert(!ret);
try {
kaguya::LuaFunction way_function = luaState["way_function"];
kaguya::LuaRef ret = way_function(this);
assert(!ret);
} catch(luaProcessingException &e) {
std::cerr << "Lua error on way " << originalOsmID << std::endl;
exit(1);
}
}

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

// Start Lua processing for relation
if (!isNativeMP && !supportsWritingRelations) return;
luaState[isNativeMP ? "way_function" : "relation_function"](this);
try {
luaState[isNativeMP ? "way_function" : "relation_function"](this);
} catch(luaProcessingException &e) {
std::cerr << "Lua error on relation " << originalOsmID << std::endl;
exit(1);
}
if (this->empty()) return;

// Assemble multipolygon
Expand Down

0 comments on commit 439c6b1

Please sign in to comment.