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:
2026-09-09 19:11:21 +04:00
co-authored by Claude Sonnet 5
parent ddf36e848a
commit a40585f419
10 changed files with 155 additions and 115 deletions
+11 -14
View File
@@ -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); }
+1 -3
View File
@@ -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;
}
+7 -9
View File
@@ -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
+28 -13
View File
@@ -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
+2 -4
View File
@@ -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();
+59 -31
View File
@@ -6,34 +6,62 @@ namespace vdm {
std::string_view error_name(Error e) noexcept {
switch (e) {
case Error::ok: return "ok";
case Error::canceled: return "canceled";
case Error::resolve_failed: return "resolve_failed";
case Error::connect_failed: return "connect_failed";
case Error::tls_failed: return "tls_failed";
case Error::connection_reset: return "connection_reset";
case Error::timeout: return "timeout";
case Error::too_many_redirects: return "too_many_redirects";
case Error::http_client_error: return "http_client_error";
case Error::http_server_error: return "http_server_error";
case Error::auth_required: return "auth_required";
case Error::forbidden: return "forbidden";
case Error::not_found: return "not_found";
case Error::range_not_satisfiable: return "range_not_satisfiable";
case Error::gone: return "gone";
case Error::server_file_changed: return "server_file_changed";
case Error::content_length_mismatch: return "content_length_mismatch";
case Error::checksum_mismatch: return "checksum_mismatch";
case Error::disk_full: return "disk_full";
case Error::io_error: return "io_error";
case Error::path_rejected: return "path_rejected";
case Error::permission_denied: return "permission_denied";
case Error::meta_corrupt: return "meta_corrupt";
case Error::meta_version_unsupported: return "meta_version_unsupported";
case Error::probe_failed: return "probe_failed";
case Error::unsupported_url_scheme: return "unsupported_url_scheme";
case Error::max_retries_exhausted: return "max_retries_exhausted";
case Error::internal: return "internal";
case Error::ok:
return "ok";
case Error::canceled:
return "canceled";
case Error::resolve_failed:
return "resolve_failed";
case Error::connect_failed:
return "connect_failed";
case Error::tls_failed:
return "tls_failed";
case Error::connection_reset:
return "connection_reset";
case Error::timeout:
return "timeout";
case Error::too_many_redirects:
return "too_many_redirects";
case Error::http_client_error:
return "http_client_error";
case Error::http_server_error:
return "http_server_error";
case Error::auth_required:
return "auth_required";
case Error::forbidden:
return "forbidden";
case Error::not_found:
return "not_found";
case Error::range_not_satisfiable:
return "range_not_satisfiable";
case Error::gone:
return "gone";
case Error::server_file_changed:
return "server_file_changed";
case Error::content_length_mismatch:
return "content_length_mismatch";
case Error::checksum_mismatch:
return "checksum_mismatch";
case Error::disk_full:
return "disk_full";
case Error::io_error:
return "io_error";
case Error::path_rejected:
return "path_rejected";
case Error::permission_denied:
return "permission_denied";
case Error::meta_corrupt:
return "meta_corrupt";
case Error::meta_version_unsupported:
return "meta_version_unsupported";
case Error::probe_failed:
return "probe_failed";
case Error::unsupported_url_scheme:
return "unsupported_url_scheme";
case Error::max_retries_exhausted:
return "max_retries_exhausted";
case Error::internal:
return "internal";
}
return "unknown";
}
@@ -48,7 +76,7 @@ bool is_retryable(Error e) noexcept {
case Error::connection_reset:
case Error::timeout:
case Error::http_server_error:
case Error::range_not_satisfiable: // stale metadata → re-probe then retry
case Error::range_not_satisfiable: // stale metadata → re-probe then retry
case Error::content_length_mismatch:
return true;
@@ -58,11 +86,11 @@ bool is_retryable(Error e) noexcept {
case Error::tls_failed:
case Error::too_many_redirects:
case Error::http_client_error:
case Error::auth_required: // resolved by credentials, not a retry
case Error::auth_required: // resolved by credentials, not a retry
case Error::forbidden:
case Error::not_found:
case Error::gone:
case Error::server_file_changed: // needs a user decision
case Error::server_file_changed: // needs a user decision
case Error::checksum_mismatch:
case Error::disk_full:
case Error::io_error:
+10 -5
View File
@@ -17,11 +17,16 @@ std::shared_ptr<LogSink> g_sink;
std::string_view log_level_name(LogLevel l) noexcept {
switch (l) {
case LogLevel::trace: return "trace";
case LogLevel::debug: return "debug";
case LogLevel::info: return "info";
case LogLevel::warn: return "warn";
case LogLevel::error: return "error";
case LogLevel::trace:
return "trace";
case LogLevel::debug:
return "debug";
case LogLevel::info:
return "info";
case LogLevel::warn:
return "warn";
case LogLevel::error:
return "error";
}
return "?";
}
+32 -33
View File
@@ -52,11 +52,11 @@ struct Registrar {
Registrar(const char *name, void (*fn)()) { registry().push_back({name, fn}); }
};
inline void report(const char *file, int line, std::string_view expr,
std::string_view detail, bool fatal) {
inline void report(const char *file, int line, std::string_view expr, std::string_view detail,
bool fatal) {
stats().failures++;
std::fprintf(stderr, " FAIL %s:%d %.*s", file, line,
static_cast<int>(expr.size()), expr.data());
std::fprintf(stderr, " FAIL %s:%d %.*s", file, line, static_cast<int>(expr.size()),
expr.data());
if (!detail.empty())
std::fprintf(stderr, " [%.*s]", static_cast<int>(detail.size()), detail.data());
std::fprintf(stderr, "\n");
@@ -110,46 +110,45 @@ inline int run_all() {
} // namespace vt
#define VT_TEST(NAME) \
static void NAME##_impl(); \
static ::vt::Registrar NAME##_reg(#NAME, &NAME##_impl); \
#define VT_TEST(NAME) \
static void NAME##_impl(); \
static ::vt::Registrar NAME##_reg(#NAME, &NAME##_impl); \
static void NAME##_impl()
#define VT_CHECK(COND) \
do { \
::vt::stats().checks++; \
if (!(COND)) \
::vt::report(__FILE__, __LINE__, #COND, {}, /*fatal=*/false); \
#define VT_CHECK(COND) \
do { \
::vt::stats().checks++; \
if (!(COND)) \
::vt::report(__FILE__, __LINE__, #COND, {}, /*fatal=*/false); \
} while (0)
#define VT_REQUIRE(COND) \
do { \
::vt::stats().checks++; \
if (!(COND)) \
::vt::report(__FILE__, __LINE__, #COND, {}, /*fatal=*/true); \
#define VT_REQUIRE(COND) \
do { \
::vt::stats().checks++; \
if (!(COND)) \
::vt::report(__FILE__, __LINE__, #COND, {}, /*fatal=*/true); \
} while (0)
#define VT_CHECK_EQ(A, B) \
#define VT_CHECK_EQ(A, B) \
do { \
::vt::stats().checks++; \
auto &&_a = (A); \
auto &&_b = (B); \
if (!(_a == _b)) \
::vt::report(__FILE__, __LINE__, #A " == " #B, \
::vt::show(_a) + " vs " + ::vt::show(_b), false); \
::vt::stats().checks++; \
auto &&_a = (A); \
auto &&_b = (B); \
if (!(_a == _b)) \
::vt::report(__FILE__, __LINE__, #A " == " #B, \
::vt::show(_a) + " vs " + ::vt::show(_b), false); \
} while (0)
#define VT_CHECK_NE(A, B) \
#define VT_CHECK_NE(A, B) \
do { \
::vt::stats().checks++; \
auto &&_a = (A); \
auto &&_b = (B); \
if (!(_a != _b)) \
::vt::report(__FILE__, __LINE__, #A " != " #B, \
::vt::show(_a) + " vs " + ::vt::show(_b), false); \
::vt::stats().checks++; \
auto &&_a = (A); \
auto &&_b = (B); \
if (!(_a != _b)) \
::vt::report(__FILE__, __LINE__, #A " != " #B, \
::vt::show(_a) + " vs " + ::vt::show(_b), false); \
} while (0)
#define VT_FAIL(MSG) \
::vt::report(__FILE__, __LINE__, "VT_FAIL", (MSG), /*fatal=*/false)
#define VT_FAIL(MSG) ::vt::report(__FILE__, __LINE__, "VT_FAIL", (MSG), /*fatal=*/false)
#endif // VDM_TESTS_VTEST_HPP
+3 -1
View File
@@ -1,4 +1,6 @@
// vtest_main.cpp — shared entry point for every CORE test binary.
#include "vtest.hpp"
int main() { return ::vt::run_all(); }
int main() {
return ::vt::run_all();
}
+2 -2
View File
@@ -48,8 +48,8 @@ VT_TEST(log_forwards_to_sink_with_format) {
VT_TEST(log_level_filter_skips_below_min) {
SinkGuard g;
auto count = std::make_shared<int>(0);
vdm::set_log_sink(std::make_shared<CallbackSink>(
[count](const LogRecord &) { ++*count; }, LogLevel::warn));
vdm::set_log_sink(
std::make_shared<CallbackSink>([count](const LogRecord &) { ++*count; }, LogLevel::warn));
VDM_LOG_DEBUG("x", "no");
VDM_LOG_INFO("x", "no");