core: clang-format pass against the landed root .clang-format
Pure formatting, no behaviour change. PKG landed .clang-format (Google base, 4-space indent, 100 cols); this brings util/ and the test harness into conformance so `clang-format --dry-run -Werror` is clean. Build and all six test binaries unchanged and green. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HPPSGhiArbvQgwC2DNiURS
This commit is contained in:
@@ -49,12 +49,12 @@ enum class Error : std::uint16_t {
|
||||
// --- local I/O ---
|
||||
disk_full = 500,
|
||||
io_error,
|
||||
path_rejected, // outside allowed roots or not writable
|
||||
permission_denied, // EACCES on the destination
|
||||
path_rejected, // outside allowed roots or not writable
|
||||
permission_denied, // EACCES on the destination
|
||||
|
||||
// --- resume metadata ---
|
||||
meta_corrupt = 600, // bad magic / failed CRC
|
||||
meta_version_unsupported, // written by a newer engine
|
||||
meta_corrupt = 600, // bad magic / failed CRC
|
||||
meta_version_unsupported, // written by a newer engine
|
||||
|
||||
// --- probe ---
|
||||
probe_failed = 700,
|
||||
@@ -80,20 +80,17 @@ enum class Error : std::uint16_t {
|
||||
// std::string here is fine.
|
||||
struct ErrorInfo {
|
||||
Error code = Error::internal;
|
||||
std::string context; // human-readable, for logs and event.notify bodies
|
||||
int http_status = 0; // 0 when not HTTP-derived
|
||||
bool retryable = false; // snapshot of is_retryable(code) at construction, may be
|
||||
// overridden by the caller (e.g. probe_failed)
|
||||
Error cause = Error::ok; // underlying error when `code` is a wrapper
|
||||
// (max_retries_exhausted)
|
||||
std::string context; // human-readable, for logs and event.notify bodies
|
||||
int http_status = 0; // 0 when not HTTP-derived
|
||||
bool retryable = false; // snapshot of is_retryable(code) at construction, may be
|
||||
// overridden by the caller (e.g. probe_failed)
|
||||
Error cause = Error::ok; // underlying error when `code` is a wrapper
|
||||
// (max_retries_exhausted)
|
||||
|
||||
ErrorInfo() = default;
|
||||
|
||||
explicit ErrorInfo(Error c, std::string ctx = {}, int status = 0)
|
||||
: code(c),
|
||||
context(std::move(ctx)),
|
||||
http_status(status),
|
||||
retryable(is_retryable(c)) {}
|
||||
: code(c), context(std::move(ctx)), http_status(status), retryable(is_retryable(c)) {}
|
||||
|
||||
[[nodiscard]] std::string_view name() const noexcept { return error_name(code); }
|
||||
|
||||
|
||||
@@ -61,9 +61,7 @@ class EventBus {
|
||||
auto &slot = channels_[std::type_index(typeid(E))];
|
||||
slot.push_back(Entry{
|
||||
tok,
|
||||
[h = std::move(handler)](const void *ev) {
|
||||
h(*static_cast<const E *>(ev));
|
||||
},
|
||||
[h = std::move(handler)](const void *ev) { h(*static_cast<const E *>(ev)); },
|
||||
});
|
||||
return tok;
|
||||
}
|
||||
|
||||
@@ -45,8 +45,7 @@ class LogSink {
|
||||
class CallbackSink final : public LogSink {
|
||||
public:
|
||||
using Fn = std::function<void(const LogRecord &)>;
|
||||
explicit CallbackSink(Fn fn, LogLevel min = LogLevel::trace)
|
||||
: fn_(std::move(fn)), min_(min) {}
|
||||
explicit CallbackSink(Fn fn, LogLevel min = LogLevel::trace) : fn_(std::move(fn)), min_(min) {}
|
||||
void write(const LogRecord &r) override { fn_(r); }
|
||||
[[nodiscard]] bool enabled(LogLevel l) const override { return l >= min_; }
|
||||
|
||||
@@ -64,21 +63,20 @@ void log_emit(LogLevel, std::string_view category, std::string message);
|
||||
|
||||
namespace detail {
|
||||
[[nodiscard]] bool log_wants(LogLevel); // sink installed && sink.enabled(level)
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
} // namespace vdm
|
||||
|
||||
#define VDM_LOG(level, category, ...) \
|
||||
#define VDM_LOG(level, category, ...) \
|
||||
do { \
|
||||
if (::vdm::detail::log_wants(level)) \
|
||||
::vdm::log_emit((level), (category), \
|
||||
std::format(__VA_ARGS__)); \
|
||||
if (::vdm::detail::log_wants(level)) \
|
||||
::vdm::log_emit((level), (category), std::format(__VA_ARGS__)); \
|
||||
} while (0)
|
||||
|
||||
#define VDM_LOG_TRACE(cat, ...) VDM_LOG(::vdm::LogLevel::trace, cat, __VA_ARGS__)
|
||||
#define VDM_LOG_DEBUG(cat, ...) VDM_LOG(::vdm::LogLevel::debug, cat, __VA_ARGS__)
|
||||
#define VDM_LOG_INFO(cat, ...) VDM_LOG(::vdm::LogLevel::info, cat, __VA_ARGS__)
|
||||
#define VDM_LOG_WARN(cat, ...) VDM_LOG(::vdm::LogLevel::warn, cat, __VA_ARGS__)
|
||||
#define VDM_LOG_INFO(cat, ...) VDM_LOG(::vdm::LogLevel::info, cat, __VA_ARGS__)
|
||||
#define VDM_LOG_WARN(cat, ...) VDM_LOG(::vdm::LogLevel::warn, cat, __VA_ARGS__)
|
||||
#define VDM_LOG_ERROR(cat, ...) VDM_LOG(::vdm::LogLevel::error, cat, __VA_ARGS__)
|
||||
|
||||
#endif // VDM_UTIL_LOG_HPP
|
||||
|
||||
@@ -37,7 +37,9 @@ class [[nodiscard]] Result {
|
||||
!std::is_same_v<std::remove_cvref_t<U>, Result>>>
|
||||
Result(U &&value) : exp_(std::in_place, std::forward<U>(value)) {}
|
||||
|
||||
Result() requires std::is_default_constructible_v<T> : exp_(std::in_place) {}
|
||||
Result()
|
||||
requires std::is_default_constructible_v<T>
|
||||
: exp_(std::in_place) {}
|
||||
|
||||
// Failure construction: implicit from an ErrorInfo/Err.
|
||||
Result(ErrorInfo error) : exp_(std::unexpected(std::move(error))) {}
|
||||
@@ -71,18 +73,30 @@ class [[nodiscard]] Result {
|
||||
// Monadic forwarding — see std::expected. `and_then` chains Result-returning
|
||||
// callables; `transform` maps the value; `transform_error` rewrites the failure.
|
||||
template <class F>
|
||||
auto and_then(F &&f) & { return exp_.and_then(std::forward<F>(f)); }
|
||||
auto and_then(F &&f) & {
|
||||
return exp_.and_then(std::forward<F>(f));
|
||||
}
|
||||
template <class F>
|
||||
auto and_then(F &&f) const & { return exp_.and_then(std::forward<F>(f)); }
|
||||
auto and_then(F &&f) const & {
|
||||
return exp_.and_then(std::forward<F>(f));
|
||||
}
|
||||
template <class F>
|
||||
auto and_then(F &&f) && { return std::move(exp_).and_then(std::forward<F>(f)); }
|
||||
auto and_then(F &&f) && {
|
||||
return std::move(exp_).and_then(std::forward<F>(f));
|
||||
}
|
||||
|
||||
template <class F>
|
||||
auto transform(F &&f) & { return exp_.transform(std::forward<F>(f)); }
|
||||
auto transform(F &&f) & {
|
||||
return exp_.transform(std::forward<F>(f));
|
||||
}
|
||||
template <class F>
|
||||
auto transform(F &&f) const & { return exp_.transform(std::forward<F>(f)); }
|
||||
auto transform(F &&f) const & {
|
||||
return exp_.transform(std::forward<F>(f));
|
||||
}
|
||||
template <class F>
|
||||
auto transform(F &&f) && { return std::move(exp_).transform(std::forward<F>(f)); }
|
||||
auto transform(F &&f) && {
|
||||
return std::move(exp_).transform(std::forward<F>(f));
|
||||
}
|
||||
|
||||
template <class F>
|
||||
auto transform_error(F &&f) const & {
|
||||
@@ -116,7 +130,9 @@ class [[nodiscard]] Result<void> {
|
||||
};
|
||||
|
||||
// Explicit success sentinel for Result<void> returns that reads better than `return {}`.
|
||||
inline Result<void> ok() { return {}; }
|
||||
inline Result<void> ok() {
|
||||
return {};
|
||||
}
|
||||
|
||||
} // namespace vdm
|
||||
|
||||
@@ -135,11 +151,10 @@ inline Result<void> ok() { return {}; }
|
||||
|
||||
// VDM_TRY_ASSIGN(decl, expr): bind `decl` to the value of a successful Result, else
|
||||
// return its error. Usage: VDM_TRY_ASSIGN(auto n, read_some());
|
||||
#define VDM_TRY_ASSIGN(decl, expr) \
|
||||
auto VDM_DETAIL_CAT(_vdm_tmp_, __LINE__) = (expr); \
|
||||
if (!VDM_DETAIL_CAT(_vdm_tmp_, __LINE__).has_value()) \
|
||||
return ::vdm::ErrorInfo( \
|
||||
std::move(VDM_DETAIL_CAT(_vdm_tmp_, __LINE__)).error()); \
|
||||
#define VDM_TRY_ASSIGN(decl, expr) \
|
||||
auto VDM_DETAIL_CAT(_vdm_tmp_, __LINE__) = (expr); \
|
||||
if (!VDM_DETAIL_CAT(_vdm_tmp_, __LINE__).has_value()) \
|
||||
return ::vdm::ErrorInfo(std::move(VDM_DETAIL_CAT(_vdm_tmp_, __LINE__)).error()); \
|
||||
decl = *std::move(VDM_DETAIL_CAT(_vdm_tmp_, __LINE__))
|
||||
|
||||
#endif // VDM_UTIL_RESULT_HPP
|
||||
|
||||
@@ -46,13 +46,11 @@ class ThreadPool {
|
||||
// Enqueue `fn(args...)`; returns a future for its result. Throws std::runtime_error
|
||||
// if the pool is already shutting down.
|
||||
template <class F, class... Args>
|
||||
auto submit(F &&fn, Args &&...args)
|
||||
-> std::future<std::invoke_result_t<F, Args...>> {
|
||||
auto submit(F &&fn, Args &&...args) -> std::future<std::invoke_result_t<F, Args...>> {
|
||||
using R = std::invoke_result_t<F, Args...>;
|
||||
|
||||
auto task = std::make_shared<std::packaged_task<R()>>(
|
||||
[f = std::forward<F>(fn),
|
||||
... a = std::forward<Args>(args)]() mutable -> R {
|
||||
[f = std::forward<F>(fn), ... a = std::forward<Args>(args)]() mutable -> R {
|
||||
return std::invoke(std::move(f), std::move(a)...);
|
||||
});
|
||||
std::future<R> fut = task->get_future();
|
||||
|
||||
Reference in New Issue
Block a user