Fix C++ review findings in pipeline: k-prefixed enum values, include ordering, populated validation error messages, conventional const notation, and endl replaced with newline

This commit is contained in:
Aaron Po
2026-08-23 15:45:35 -04:00
parent 754bd6764e
commit 9bec9b1edd
6 changed files with 34 additions and 24 deletions

View File

@@ -8,12 +8,14 @@
#include <algorithm>
#include <array>
#include <boost/json.hpp>
#include <cctype>
#include <format>
#include <span>
#include <string>
#include <string_view>
#include <boost/json.hpp>
namespace {
/**
* String trimming: removes leading and trailing whitespace
@@ -66,11 +68,18 @@ bool ReadRequiredTrimmedStringField(const boost::json::object& obj,
std::string* error_out) {
const boost::json::value* field = obj.if_contains(key);
if (field == nullptr || !field->is_string()) {
if (error_out != nullptr) {
*error_out =
std::format("Missing or invalid string field: {}", key);
}
return false;
}
const auto& string_value = field->as_string();
out = Trim(std::string_view(string_value.data(), string_value.size()));
if (out.empty() && error_out != nullptr) {
*error_out = std::format("Field must not be empty: {}", key);
}
return !out.empty();
}