@@ -10,10 +10,10 @@ bool supportsRemappingShapefiles = false;
1010
1111int 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