diff options
| author | Dmytro Ivanov <[email protected]> | 2025-04-23 10:54:22 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-04-23 10:54:22 +0200 |
| commit | 199553c86444dcd9c4cff91165938dbd9a5b4bbb (patch) | |
| tree | 017231616e164717b112dae1faab05f1d8573f10 /src | |
| parent | make sure to call MakeSafeAbsolutePathÍnPlace where appropriate (#363) (diff) | |
| download | zen-199553c86444dcd9c4cff91165938dbd9a5b4bbb.tar.xz zen-199553c86444dcd9c4cff91165938dbd9a5b4bbb.zip | |
Make plugin loading errors non fatal (#364)
make plugin loading errors non fatal
Diffstat (limited to 'src')
| -rw-r--r-- | src/zenhttp/httpserver.cpp | 48 | ||||
| -rw-r--r-- | src/zenhttp/transports/dlltransport.cpp | 25 | ||||
| -rw-r--r-- | src/zenhttp/transports/dlltransport.h | 2 |
3 files changed, 46 insertions, 29 deletions
diff --git a/src/zenhttp/httpserver.cpp b/src/zenhttp/httpserver.cpp index d12f89a92..764f2a2a7 100644 --- a/src/zenhttp/httpserver.cpp +++ b/src/zenhttp/httpserver.cpp @@ -831,7 +831,6 @@ CreateHttpServerPlugin(const HttpServerPluginConfig& PluginConfig) const std::string& PluginName = PluginConfig.PluginName; ZEN_INFO("using '{}' plugin HTTP server implementation", PluginName) - Ref<HttpPluginServer> Server{CreateHttpPluginServer()}; if (PluginName.starts_with("builtin:"sv)) { @@ -845,28 +844,41 @@ CreateHttpServerPlugin(const HttpServerPluginConfig& PluginConfig) { Plugin = CreateAsioTransportPlugin(); } + else + { + ZEN_WARN("Unknown builtin plugin '{}'", PluginName) + return {}; + } + + ZEN_ASSERT(!Plugin.IsNull()); - if (!Plugin.IsNull()) + for (const std::pair<std::string, std::string>& Option : PluginConfig.PluginOptions) { - for (const std::pair<std::string, std::string>& Option : PluginConfig.PluginOptions) - { - Plugin->Configure(Option.first.c_str(), Option.second.c_str()); - } - Server->AddPlugin(Plugin); + Plugin->Configure(Option.first.c_str(), Option.second.c_str()); } + + Ref<HttpPluginServer> Server{CreateHttpPluginServer()}; + Server->AddPlugin(Plugin); + return Server; +# else + ZEN_WARN("Builtin plugin '{}' is not supported", PluginName) + return {}; # endif } - else + + Ref<DllTransportPlugin> DllPlugin{CreateDllTransportPlugin()}; + if (!DllPlugin->LoadDll(PluginName)) { - Ref<DllTransportPlugin> DllPlugin{CreateDllTransportPlugin()}; - DllPlugin->LoadDll(PluginName); - for (const std::pair<std::string, std::string>& Option : PluginConfig.PluginOptions) - { - DllPlugin->ConfigureDll(PluginName, Option.first.c_str(), Option.second.c_str()); - } - Server->AddPlugin(DllPlugin); + return {}; + } + + for (const std::pair<std::string, std::string>& Option : PluginConfig.PluginOptions) + { + DllPlugin->ConfigureDll(PluginName, Option.first.c_str(), Option.second.c_str()); } + Ref<HttpPluginServer> Server{CreateHttpPluginServer()}; + Server->AddPlugin(DllPlugin); return Server; } #endif @@ -888,7 +900,11 @@ CreateHttpServer(const HttpServerConfig& Config) for (const HttpServerPluginConfig& PluginConfig : Config.PluginConfigs) { - Server->AddServer(CreateHttpServerPlugin(PluginConfig)); + Ref<HttpServer> PluginServer = CreateHttpServerPlugin(PluginConfig); + if (!PluginServer.IsNull()) + { + Server->AddServer(PluginServer); + } } return Server; diff --git a/src/zenhttp/transports/dlltransport.cpp b/src/zenhttp/transports/dlltransport.cpp index dd05f6f0c..fb3dd23b5 100644 --- a/src/zenhttp/transports/dlltransport.cpp +++ b/src/zenhttp/transports/dlltransport.cpp @@ -55,7 +55,7 @@ public: virtual const char* GetDebugName() override; virtual bool IsAvailable() override; - virtual void LoadDll(std::string_view Name) override; + virtual bool LoadDll(std::string_view Name) override; virtual void ConfigureDll(std::string_view Name, const char* OptionTag, const char* OptionValue) override; private: @@ -172,7 +172,7 @@ DllTransportPluginImpl::ConfigureDll(std::string_view Name, const char* OptionTa } } -void +bool DllTransportPluginImpl::LoadDll(std::string_view Name) { RwLock::ExclusiveLockScope _(m_Lock); @@ -190,9 +190,8 @@ DllTransportPluginImpl::LoadDll(std::string_view Name) if (!DllHandle) { - std::error_code Ec = MakeErrorCodeFromLastError(); - - throw std::system_error(Ec, fmt::format("failed to load transport DLL from '{}'", DllPath)); + ZEN_WARN("Failed to load transport DLL from '{}' due to '{}'", DllPath, GetLastErrorAsString()) + return false; } PfnGetTransportPluginVersion GetVersion = (PfnGetTransportPluginVersion)GetProcAddress(DllHandle, "GetTransportPluginVersion"); @@ -216,17 +215,18 @@ DllTransportPluginImpl::LoadDll(std::string_view Name) if (GetVersion && !bValidApiVersion) { - throw std::system_error( - Ec, - fmt::format("invalid API version '{}' detected in transport DLL loaded from '{}', supported API version '{}'", - APIVersion, - DllPath, - kTransportApiVersion)); + ZEN_WARN("Failed to load transport DLL from '{}' due to invalid API version {}, supported API version is {}", + DllPath, + APIVersion, + kTransportApiVersion) } else { - throw std::system_error(Ec, fmt::format("API mismatch detected in transport DLL loaded from '{}'", DllPath)); + ZEN_WARN("Failed to load transport DLL from '{}' due to not finding GetTransportPluginVersion or CreateTransportPlugin", + DllPath) } + + return false; } LoadedDll NewDll; @@ -238,6 +238,7 @@ DllTransportPluginImpl::LoadDll(std::string_view Name) NewDll.Plugin = CreatePlugin(NewDll.Logger); m_Transports.emplace_back(std::move(NewDll)); + return true; } DllTransportPlugin* diff --git a/src/zenhttp/transports/dlltransport.h b/src/zenhttp/transports/dlltransport.h index 9346a10ce..c49f888da 100644 --- a/src/zenhttp/transports/dlltransport.h +++ b/src/zenhttp/transports/dlltransport.h @@ -15,7 +15,7 @@ namespace zen { class DllTransportPlugin : public TransportPlugin { public: - virtual void LoadDll(std::string_view Name) = 0; + virtual bool LoadDll(std::string_view Name) = 0; virtual void ConfigureDll(std::string_view Name, const char* OptionTag, const char* OptionValue) = 0; }; |