3#include "../connection/connection.hpp"
4#include "../query/core.hpp"
5#include "../results/result.hpp"
9#include <source_location>
21 const std::source_location& location = std::source_location::current())
23 std::format(
"[{}:{}] {}", location.file_name(), location.line(), message)) {}
30 return std::format(
"Connection error: {} (Code: {})", error.
message, error.
error_code);
37 return std::format(
"Query error: {}", error.
message);
44 return std::format(
"Result processing error: {}", error.
message);
57template <
typename T,
typename E>
58T&
value_or_throw(std::expected<T, E>& result,
const std::string& context =
"",
59 const std::source_location& location = std::source_location::current()) {
62 if (!context.empty()) {
63 message = std::format(
"{}: ", context);
68 return result.value();
74template <
typename T,
typename E>
75T
value_or_throw(std::expected<T, E>&& result,
const std::string& context =
"",
76 const std::source_location& location = std::source_location::current()) {
79 if (!context.empty()) {
80 message = std::format(
"{}: ", context);
85 return std::move(result.value());
92void throw_if_failed(
const std::expected<void, E>& result,
const std::string& context =
"",
93 const std::source_location& location = std::source_location::current()) {
96 if (!context.empty()) {
97 message = std::format(
"{}: ", context);
Base exception class for relx errors.
RelxException(const std::string &message, const std::source_location &location=std::source_location::current())
std::string format_error(const connection::ConnectionError &error)
Format a ConnectionError for exception messages.
void throw_if_failed(const std::expected< void, E > &result, const std::string &context="", const std::source_location &location=std::source_location::current())
Function to check and throw on error with no return value.
T & value_or_throw(std::expected< T, E > &result, const std::string &context="", const std::source_location &location=std::source_location::current())
Function to extract a value from an expected or throw on error.
Error type for database connection operations.
Error type for query operations.
Error type for result processing operations.