Skip to content

Commit

Permalink
cleanup: clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
umegane committed Sep 18, 2024
1 parent e60e8ca commit 7449bd6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 23 deletions.
23 changes: 1 addition & 22 deletions include/limestone/api/limestone_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <iostream>
#include <filesystem>


namespace limestone::api {

class limestone_exception : public std::runtime_error {
Expand Down Expand Up @@ -54,26 +55,4 @@ class limestone_io_exception : public limestone_exception {
}
};

// Macro to throw exceptions with file and line information

#define THROW_LIMESTONE_EXCEPTION(message) \
throw limestone_exception(std::string(message) + " (at " + std::filesystem::path(__FILE__).filename().string() + ":" + std::to_string(__LINE__) + ")")

#define THROW_LIMESTONE_IO_EXCEPTION(message, error_code) \
throw limestone_io_exception(std::string(message) + " (at " + std::filesystem::path(__FILE__).filename().string() + ":" + std::to_string(__LINE__) + ")", error_code)

#define LOG_AND_THROW_EXCEPTION(message) \
{ \
LOG_LP(ERROR) << message; \
THROW_LIMESTONE_EXCEPTION(message); \
}

#define LOG_AND_THROW_IO_EXCEPTION(message, error_code) \
{ \
std::string full_message = limestone_io_exception::format_message(message, error_code); \
LOG_LP(ERROR) << full_message; \
THROW_LIMESTONE_IO_EXCEPTION(message, error_code); \
}


} // namespace limestone::api
2 changes: 1 addition & 1 deletion src/limestone/compaction_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "compaction_catalog.h"
#include "logging_helper.h"
#include "limestone/api/epoch_id_type.h"
#include "limestone/api/limestone_exception.h"
#include "limestone_exception_helper.h"

namespace limestone::internal {

Expand Down
45 changes: 45 additions & 0 deletions src/limestone/limestone_exception_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <glog/logging.h>
#include <limestone/logging.h>
#include "logging_helper.h"

#include <limestone/api/limestone_exception.h>

#pragma once

namespace limestone {

using limestone::api::limestone_exception;
using limestone::api::limestone_io_exception;

inline void throw_limestone_exception(const std::string& message, const char* file, int line) {
throw limestone_exception(message + " (at " + std::filesystem::path(file).filename().string() + ":" + std::to_string(line) + ")");
}

inline void throw_limestone_io_exception(const std::string& message, int error_code, const char* file, int line) {
throw limestone_io_exception(message + " (at " + std::filesystem::path(file).filename().string() + ":" + std::to_string(line) + ")", error_code);
}

inline void log_and_throw_exception(const std::string& message, const char* file, int line) {
LOG_LP(ERROR) << message;
throw_limestone_exception(message, file, line);
}

inline void log_and_throw_io_exception(const std::string& message, int error_code, const char* file, int line) {
std::string full_message = limestone_io_exception::format_message(message, error_code);
LOG_LP(ERROR) << full_message;
throw_limestone_io_exception(message, error_code, file, line);
}

// NOLINTNEXTLINE
#define THROW_LIMESTONE_EXCEPTION(message) throw_limestone_exception(message, __FILE__, __LINE__)

// NOLINTNEXTLINE
#define THROW_LIMESTONE_IO_EXCEPTION(message, error_code) throw_limestone_io_exception(message, error_code, __FILE__, __LINE__)

// NOLINTNEXTLINE
#define LOG_AND_THROW_EXCEPTION(message) log_and_throw_exception(message, __FILE__, __LINE__)

// NOLINTNEXTLINE
#define LOG_AND_THROW_IO_EXCEPTION(message, error_code) log_and_throw_io_exception(message, error_code, __FILE__, __LINE__)

} // namespace limestone

0 comments on commit 7449bd6

Please sign in to comment.