Lua may call C++ functions with throw. Catch them
authorRobin Gareus <robin@gareus.org>
Fri, 18 Aug 2017 23:05:08 +0000 (01:05 +0200)
committerRobin Gareus <robin@gareus.org>
Fri, 18 Aug 2017 23:06:44 +0000 (01:06 +0200)
gtk2_ardour/ardour_ui.cc
gtk2_ardour/luainstance.cc
gtk2_ardour/luawindow.cc
gtk2_ardour/processor_box.cc
gtk2_ardour/session_dialog.cc

index d3b07badb933a82dca8ad1fb73a67f9af59b9b18..8d931bbbd39c3dc21b36bfbdc741f323bef73efc 100644 (file)
@@ -3927,8 +3927,7 @@ ARDOUR_UI::route_setup_info (const std::string& script_path)
                }
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
-               return rv;
-       }
+       } catch (...) { }
        return rv;
 }
 
@@ -3976,6 +3975,8 @@ ARDOUR_UI::meta_route_setup (const std::string& script_path)
                }
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
+       } catch (...) {
+               display_insufficient_ports_message ();
        }
 }
 
@@ -4006,6 +4007,8 @@ ARDOUR_UI::meta_session_setup (const std::string& script_path)
                }
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
+       } catch (...) {
+               display_insufficient_ports_message ();
        }
 }
 
index 15ab49e884dd8de95ef54d88d1e91994c15ab9bd..fe4276c39a9c2d22910bd00d482906e294573376 100644 (file)
@@ -1161,6 +1161,11 @@ LuaInstance::init ()
                _lua_clear = new luabridge::LuaRef(lua_mgr["clear"]);
 
        } catch (luabridge::LuaException const& e) {
+               fatal << string_compose (_("programming error: %1"),
+                               std::string ("Failed to setup Lua action interpreter") + e.what ())
+                       << endmsg;
+               abort(); /*NOTREACHED*/
+       } catch (...) {
                fatal << string_compose (_("programming error: %1"),
                                X_("Failed to setup Lua action interpreter"))
                        << endmsg;
@@ -1229,7 +1234,7 @@ LuaInstance::set_state (const XMLNode& node)
                                (*_lua_load)(std::string ((const char*)buf, size));
                        } catch (luabridge::LuaException const& e) {
                                cerr << "LuaException:" << e.what () << endl;
-                       }
+                       } catch (...) { }
                        for (int i = 0; i < 9; ++i) {
                                std::string name;
                                if (lua_action_name (i, name)) {
@@ -1249,7 +1254,7 @@ LuaInstance::set_state (const XMLNode& node)
                                SlotChanged (p->id(), p->name(), p->signals()); /* EMIT SIGNAL */
                        } catch (luabridge::LuaException const& e) {
                                cerr << "LuaException:" << e.what () << endl;
-                       }
+                       } catch (...) { }
                }
        }
 
@@ -1340,6 +1345,10 @@ LuaInstance::interactive_add (LuaScriptInfo::ScriptType type, int id)
                                string msg = string_compose (_("Loading Session script '%1' failed: %2"), spd.name(), e.what ());
                                Gtk::MessageDialog am (msg);
                                am.run ();
+                       } catch (...) {
+                               string msg = string_compose (_("Loading Session script '%1' failed: %2"), spd.name(), "Unknown Exception");
+                               Gtk::MessageDialog am (msg);
+                               am.run ();
                        }
                default:
                        break;
@@ -1386,7 +1395,7 @@ LuaInstance::call_action (const int id)
                lua.collect_garbage_step ();
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
-       }
+       } catch (...) { }
 }
 
 void
@@ -1403,7 +1412,7 @@ LuaInstance::render_icon (int i, cairo_t* cr, int w, int h, uint32_t clr)
                 (*_lua_render_icon)(i + 1, (Cairo::Context *)&ctx, w, h, clr);
         } catch (luabridge::LuaException const& e) {
                 cerr << "LuaException:" << e.what () << endl;
-        }
+        } catch (...) { }
 }
 
 bool
@@ -1429,6 +1438,8 @@ LuaInstance::set_lua_action (
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
                return false;
+       } catch (...) {
+               return false;
        }
        _session->set_dirty ();
        return true;
@@ -1442,6 +1453,8 @@ LuaInstance::remove_lua_action (const int id)
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
                return false;
+       } catch (...) {
+               return false;
        }
        ActionChanged (id, ""); /* EMIT SIGNAL */
        _session->set_dirty ();
@@ -1463,8 +1476,7 @@ LuaInstance::lua_action_name (const int id, std::string& rv)
                return true;
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
-               return false;
-       }
+       } catch (...) { }
        return false;
 }
 
@@ -1494,7 +1506,7 @@ LuaInstance::lua_action_has_icon (const int id)
                }
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
-       }
+       } catch (...) { }
        return false;
 }
 
@@ -1529,8 +1541,7 @@ LuaInstance::lua_action (const int id, std::string& name, std::string& script, L
                return true;
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
-               return false;
-       }
+       } catch (...) { }
        return false;
 }
 
@@ -1553,7 +1564,7 @@ LuaInstance::register_lua_slot (const std::string& name, const std::string& scri
                }
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
-       }
+       } catch (...) { }
 
        if (ah.none ()) {
                cerr << "Script registered no hooks." << endl;
@@ -1570,7 +1581,7 @@ LuaInstance::register_lua_slot (const std::string& name, const std::string& scri
                return true;
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
-       }
+       } catch (...) { }
        _session->set_dirty ();
        return false;
 }
@@ -1656,11 +1667,13 @@ LuaCallback::LuaCallback (Session *s,
        }
 
        try {
-       const std::string& bytecode = LuaScripting::get_factory_bytecode (script);
-       (*_lua_add)(name, script, bytecode, tbl_arg);
+               const std::string& bytecode = LuaScripting::get_factory_bytecode (script);
+               (*_lua_add)(name, script, bytecode, tbl_arg);
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
                throw failed_constructor ();
+       } catch (...) {
+               throw failed_constructor ();
        }
 
        _id.reset ();
@@ -1699,7 +1712,7 @@ LuaCallback::LuaCallback (Session *s, XMLNode & node)
                (*_lua_load)(std::string ((const char*)buf, size));
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
-       }
+       } catch (...) { }
        g_free (buf);
 
        set_session (s);
@@ -1859,6 +1872,11 @@ LuaCallback::init (void)
                _lua_load = new luabridge::LuaRef(lua_mgr["restore"]);
 
        } catch (luabridge::LuaException const& e) {
+               fatal << string_compose (_("programming error: %1"),
+                               std::string ("Failed to setup Lua callback interpreter: ") + e.what ())
+                       << endmsg;
+               abort(); /*NOTREACHED*/
+       } catch (...) {
                fatal << string_compose (_("programming error: %1"),
                                X_("Failed to setup Lua callback interpreter"))
                        << endmsg;
@@ -1907,7 +1925,7 @@ LuaCallback::lua_slot (std::string& name, std::string& script, ActionHook& ah, A
        } catch (luabridge::LuaException const& e) {
                cerr << "LuaException:" << e.what () << endl;
                return false;
-       }
+       } catch (...) { }
        return false;
 }
 
index 72f0af6980195e820793800344d2dcf9eac8682c..89a1d387aa490cfdb1ea058c80a803842d8d1cfc 100644 (file)
@@ -286,6 +286,12 @@ LuaWindow::run_script ()
                        }
                } catch (luabridge::LuaException const& e) {
                        append_text (string_compose (_("LuaException: %1"), e.what()));
+               } catch (Glib::Exception const& e) {
+                       append_text (string_compose (_("Glib Exception: %1"), e.what()));
+               } catch (std::exception const& e) {
+                       append_text (string_compose (_("C++ Exception: %1"), e.what()));
+               } catch (...) {
+                       append_text (string_compose (_("C++ Exception: %1"), "..."));
                }
        } else {
                // script with factory method
@@ -304,6 +310,12 @@ LuaWindow::run_script ()
                        lua->do_command ("factory = nil;");
                } catch (luabridge::LuaException const& e) {
                        append_text (string_compose (_("LuaException: %1"), e.what()));
+               } catch (Glib::Exception const& e) {
+                       append_text (string_compose (_("Glib Exception: %1"), e.what()));
+               } catch (std::exception const& e) {
+                       append_text (string_compose (_("C++ Exception: %1"), e.what()));
+               } catch (...) {
+                       append_text (string_compose (_("C++ Exception: %1"), "..."));
                }
        }
 }
index a25ac0de401d4514e5b7b1f8be4d67765ef86644..543a0e23993894029918f05d3ea042d94049a05f 100644 (file)
@@ -1686,7 +1686,7 @@ ProcessorEntry::LuaPluginDisplay::render_inline (cairo_t *cr, uint32_t width)
 #ifndef NDEBUG
                cerr << "LuaException:" << e.what () << endl;
 #endif
-       }
+       } catch (...) { }
        return 0;
 }
 
index d6c17e09ac23941352ee4d08f415ae6927b4b48f..95f30ffcf7deb3e2ecc640519e627bd1d06ac27e 100644 (file)
@@ -221,8 +221,11 @@ SessionDialog::meta_master_bus_profile (std::string script_path) const
                err = lua.do_file (script_path);
        } catch (luabridge::LuaException const& e) {
                err = -1;
+       }  catch (...) {
+               err = -1;
        }
 
+
        if (err) {
                return UINT32_MAX;
        }