Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cmake_minimum_required(VERSION 4.1)

project(config-core LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_library(config-core
src/error.cpp)

target_include_directories(config-core PUBLIC include)
target_compile_features(config-core PUBLIC cxx_std_20)

if (MSVC)
target_compile_options(config-core PRIVATE /W4)
else()
target_compile_options(config-core PRIVATE
-Wall
-Wextra
-Wpedantic
)
endif()
54 changes: 54 additions & 0 deletions core/include/config/error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once

#include <cstddef>
#include <string>

namespace config {

enum class error_reason {
InvalidSyntax,
InvalidType,
MissingField,
UnknownField,
InvalidValue,
ValidationFailed,
InternalError
};

enum class error_category {
Parse,
Type,
Validation,
Internal
};

struct error_location {
std::size_t line = 0;
std::size_t column = 0;
};

class error {
public:

error(error_reason reason, error_category category, const std::string &message, error_location location) noexcept;
~error() noexcept = default;

[[nodiscard]]
error_reason reason() const noexcept;

[[nodiscard]]
error_category category() const noexcept;

[[nodiscard]]
std::string message() const noexcept;

[[nodiscard]]
error_location location() const noexcept;

protected:
error_reason reason_;
error_category category_;
std::string message_;
error_location location_;
};
}
22 changes: 22 additions & 0 deletions core/include/config/exception.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <stdexcept>
#include "error.h"

namespace config {

class config_exception : public std::runtime_error {
public:

explicit config_exception(error error)
: std::runtime_error(error.message().data()), error_(std::move(error)) {}

[[nodiscard]]
const error& original_error() const noexcept {
return error_;
}

private:
error error_;
};
}
27 changes: 27 additions & 0 deletions core/src/error.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "config/error.h"

namespace config {

error::error(const error_reason reason, const error_category category, const std::string &message, const error_location location) noexcept {
reason_ = reason;
category_ = category;
message_ = message;
location_ = location;
}

error_reason error::reason() const noexcept {
return reason_;
}

error_category error::category() const noexcept {
return category_;
}

std::string error::message() const noexcept {
return message_;
}

error_location error::location() const noexcept {
return location_;
}
}