Skip to content

Commit b87504b

Browse files
committed
fix: fix uncaught exception while loading plugins
1 parent f4e60f8 commit b87504b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/lse/PluginManager.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
7979
// Load the plugin entry.
8080
auto pluginDir = std::filesystem::canonical(ll::plugin::getPluginsRoot() / manifest.name);
8181
auto entryPath = pluginDir / manifest.entry;
82+
ENGINE_OWN_DATA()->pluginFileOrDirPath = entryPath.string();
8283

8384
// Try loadFile
8485
try {
@@ -98,7 +99,11 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
9899
plugin->onUnload([](ll::plugin::Plugin& plugin) { return true; });
99100
plugin->onEnable([](ll::plugin::Plugin& plugin) { return true; });
100101
plugin->onDisable([](ll::plugin::Plugin& plugin) { return true; });
101-
} catch (const std::exception& e) {
102+
ExitEngineScope exit;
103+
} catch (const Exception& e) {
104+
EngineScope engineScope(scriptEngine);
105+
logger.error("Failed to load plugin {0}: {1}\n{2}", manifest.name, e.message(), e.stacktrace());
106+
ExitEngineScope exit;
102107
LLSERemoveTimeTaskData(&scriptEngine);
103108
LLSERemoveAllEventListeners(&scriptEngine);
104109
LLSERemoveCmdRegister(&scriptEngine);
@@ -109,18 +114,17 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
109114

110115
EngineManager::unregisterEngine(&scriptEngine);
111116

112-
throw;
117+
return false;
113118
}
114119

115120
if (!addPlugin(manifest.name, plugin)) {
116-
throw std::runtime_error(fmt::format("failed to register plugin {}", manifest.name));
121+
throw std::runtime_error("Failed to register plugin {}"_tr(manifest.name));
117122
}
118123

119124
return true;
120125

121126
} catch (const std::exception& e) {
122-
logger.error("failed to load plugin {}: {}", manifest.name, e.what());
123-
return false;
127+
logger.error("Failed to load plugin {0}: {1}", manifest.name, e.what());
124128
}
125129

126130
return true;

0 commit comments

Comments
 (0)