*/
#pragma once
-#include <string>
-#include <cstring>
#include <cstdio>
-#include <exception>
#include <cstdlib>
+#include <cstring>
+#include <exception>
#include <sstream>
-
+#include <string>
#define Try try
class ServiceException {
public:
DECLARE_EXCEPTION_TYPE(WA::Exception, Base)
- DECLARE_EXCEPTION_TYPE(Base, InvalidAction)
DECLARE_EXCEPTION_TYPE(Base, InActive)
+ DECLARE_EXCEPTION_TYPE(Base, InvalidAction)
+ DECLARE_EXCEPTION_TYPE(Base, InvalidSharedLib)
};
class ClientException {
public:
m_libraryHandle = dlopen(m_libraryPath.c_str(), RTLD_LAZY | RTLD_LOCAL);
if (!m_libraryHandle)
{
- LogError("Unable to load library(" << m_libraryPath << "): " << dlerror());
- throw std::runtime_error("Unable to load library");
+ ThrowMsg(ServiceException::InvalidSharedLib,
+ "Unable to load library(" << m_libraryPath << "): " << dlerror());
}
}
DLLoader::~DLLoader()
#pragma once
+#include <dlfcn.h>
#include <string>
-#include <stdexcept>
+#include <exception.h>
#include <webauthn-log.h>
-#include <dlfcn.h>
namespace WA {
function_t func = (function_t)ResolveFunction(name);
if (!func)
{
- throw std::runtime_error("Trying to call unresolved function");
+ ThrowMsg(ServiceException::InvalidSharedLib,
+ "Trying to call unresolved function");
}
return func(args...);
}
* @brief Implementation of webauthn
*/
-#include <stdlib.h>
#include <signal.h>
-#include <webauthn-types.h>
-#include <webauthn-log.h>
+#include <stdlib.h>
#include <exception.h>
#include <service.h>
#include <service-file-locker.h>
+#include <webauthn-log.h>
+#include <webauthn-types.h>
#ifdef GCOV_BUILD
extern "C" void __gcov_flush(void);
manager.RegisterSocketService(std::move(service));
manager.MainLoop();
return EXIT_SUCCESS;
+ } catch (const ServiceException::InvalidSharedLib &e) {
+ LogError("Error in starting service, not supported: " << e.DumpToString());
} catch (const std::exception &e) {
LogError("Error in starting service, details:\n" << e.what());
} catch (...) {
* @brief unit tests for dl-loader
*/
-#include "test-common.h"
-
-#include <dl-loader.h>
#include <gtest/gtest.h>
-#include <webauthn-hal.h>
#include <iostream>
+#include <webauthn-hal.h>
+#include <dl-loader.h>
+#include <exception.h>
+#include "test-common.h"
namespace WA {
int ret = 0;
try{
auto dlLoader = std::make_unique<DLLoader>("invalid_so_path");
- } catch (...)
+ } catch (const ServiceException::InvalidSharedLib &e)
{
ret = -1;
+ } catch (...)
+ {
+ ret = -2;
}
EXPECT_EQ(ret, -1);
try{
auto dlLoader = std::make_unique<DLLoader>(WAH_PLUGIN_SO_PATH_HYBRID);
dlLoader->Invoke<int>("invalid_api_name");
- } catch (...)
+ } catch (const ServiceException::InvalidSharedLib &e)
{
ret = -1;
+ } catch (...)
+ {
+ ret = -2;
}
EXPECT_EQ(ret, -1);