shared.hpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /// Internal shared header file. Not intended for external use.
  2. #pragma once
  3. #include <clickhouse/client.h>
  4. #include <clickhouse/exceptions.h>
  5. #include <spdlog/logger.h>
  6. #include <exception>
  7. #include <string>
  8. namespace tsdb_shared {
  9. struct tsdb_exception : std::runtime_error {
  10. using std::runtime_error::runtime_error;
  11. tsdb_exception(const std::string& what, std::exception_ptr nested_exception)
  12. : std::runtime_error(what), nested_exception_(nested_exception) {}
  13. std::exception_ptr nested_exception() const noexcept { return nested_exception_; }
  14. private:
  15. std::exception_ptr nested_exception_ = nullptr;
  16. };
  17. void init_tsdb_env();
  18. spdlog::logger& logger();
  19. std::string random_uuid();
  20. template <typename F>
  21. auto ex_log_boundary(F&& f) try {
  22. return f();
  23. } catch (const clickhouse::Error& e) {
  24. logger().error("Unhandled stck exception: {}", e.what());
  25. throw tsdb_exception(e.what(), std::current_exception());
  26. } catch (const std::exception& e) {
  27. logger().error("Unhandled generic exception: {}", e.what());
  28. throw;
  29. }
  30. } // namespace tsdb_shared
  31. // Preludes
  32. using tsdb_shared::ex_log_boundary;
  33. using tsdb_shared::logger;