Skip to content

Commit a9dd42e

Browse files
committed
refactor: replace exception with log
1 parent a2d5199 commit a9dd42e

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/lse/PluginManager.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
4747
logger.info("loading plugin {}", manifest.name);
4848

4949
if (hasPlugin(manifest.name)) {
50-
throw std::runtime_error("plugin already loaded");
50+
logger.error("plugin already loaded");
51+
return false;
5152
}
5253

5354
auto& scriptEngine = *EngineManager::newEngine(manifest.name);
@@ -67,7 +68,8 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
6768
auto baseLibPath = self.getPluginDir() / "baselib" / BaseLibFileName;
6869
auto baseLibContent = ll::file_utils::readFile(baseLibPath);
6970
if (!baseLibContent) {
70-
throw std::runtime_error(fmt::format("failed to read BaseLib at {}", baseLibPath.string()));
71+
logger.error("failed to read BaseLib at {}", baseLibPath.string());
72+
return false;
7173
}
7274
scriptEngine.eval(baseLibContent.value());
7375

@@ -76,7 +78,8 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
7678
auto entryPath = pluginDir / manifest.entry;
7779
auto pluginEntryContent = ll::file_utils::readFile(entryPath);
7880
if (!pluginEntryContent) {
79-
throw std::runtime_error(fmt::format("failed to read plugin entry at {}", entryPath.string()));
81+
logger.error("failed to read plugin entry at {}", entryPath.string());
82+
return false;
8083
}
8184
scriptEngine.eval(pluginEntryContent.value());
8285

@@ -91,12 +94,13 @@ auto PluginManager::load(ll::plugin::Manifest manifest) -> bool {
9194

9295
EngineManager::unregisterEngine(&scriptEngine);
9396

94-
throw;
97+
// throw;
9598
}
9699

97100
auto plugin = std::make_shared<Plugin>(manifest);
98101
if (!addPlugin(manifest.name, plugin)) {
99-
throw std::runtime_error(fmt::format("failed to register plugin {}", manifest.name));
102+
logger.error("failed to register plugin {}", manifest.name);
103+
return false;
100104
}
101105

102106
return true;
@@ -124,7 +128,8 @@ auto PluginManager::unload(std::string_view name) -> bool {
124128
scriptEngine.destroy(); // TODO: use unique_ptr to manage the engine.
125129

126130
if (!erasePlugin(name)) {
127-
throw std::runtime_error(fmt::format("failed to unregister plugin {}", name));
131+
logger.error("failed to unregister plugin {}", name);
132+
return false;
128133
}
129134

130135
return false;

0 commit comments

Comments
 (0)