28#include "iceberg/compat/compiler.h"
34#define ICEBERG_BUILDER_RETURN_IF_ERROR(result) \
35 if (auto&& result_name = result; !result_name) [[unlikely]] { \
36 errors_.emplace_back(std::move(result_name.error())); \
40#define ICEBERG_BUILDER_ASSIGN_OR_RETURN_IMPL(result_name, lhs, rexpr) \
41 auto&& result_name = (rexpr); \
42 ICEBERG_BUILDER_RETURN_IF_ERROR(result_name) \
43 lhs = std::move(result_name.value());
45#define ICEBERG_BUILDER_ASSIGN_OR_RETURN(lhs, rexpr) \
46 ICEBERG_BUILDER_ASSIGN_OR_RETURN_IMPL( \
47 ICEBERG_ASSIGN_OR_RAISE_NAME(result_, __COUNTER__), lhs, rexpr)
49#define ICEBERG_BUILDER_ASSIGN_OR_RETURN_WITH_ERROR_IMPL(result_name, lhs, rexpr, ...) \
50 auto&& result_name = (rexpr); \
51 if (!result_name) [[unlikely]] { \
52 AddError(::iceberg::ErrorKind::kInvalidArgument, __VA_ARGS__); \
55 lhs = std::move(result_name.value());
57#define ICEBERG_BUILDER_ASSIGN_OR_RETURN_WITH_ERROR(lhs, rexpr, ...) \
58 ICEBERG_BUILDER_ASSIGN_OR_RETURN_WITH_ERROR_IMPL( \
59 ICEBERG_ASSIGN_OR_RAISE_NAME(result_, __COUNTER__), lhs, rexpr, __VA_ARGS__)
61#define ICEBERG_BUILDER_CHECK(expr, ...) \
63 if (!(expr)) [[unlikely]] { \
64 AddError(::iceberg::ErrorKind::kInvalidArgument, __VA_ARGS__); \
117#if ICEBERG_CXX20_COMPAT
118 template <
typename... Args>
121 RecordError({kind, std::format(fmt, std::forward<Args>(args)...)});
125 template <
typename... Args>
129 {kind, std::format(fmt, std::forward<Args>(args)...)});
142#if ICEBERG_CXX20_COMPAT
144 RecordError(std::move(err));
165#if ICEBERG_CXX20_COMPAT
167 RecordError(std::move(err.error()));
172 static_cast<ErrorCollector&
>(self).RecordError(std::move(err.error()));
175 auto& AddError(
this auto& self, std::unexpected<Error> err) {
176 static_cast<ErrorCollector&
>(self).RecordError(std::move(err.error()));
184 [[nodiscard]]
bool has_errors()
const {
return !errors_.empty(); }
189 [[nodiscard]]
size_t error_count()
const {
return errors_.size(); }
201 if (!errors_.empty()) {
202 std::string error_msg =
"Validation failed due to the following errors:\n";
203 bool all_retryable =
true;
204 for (
const auto& [kind, message] : errors_) {
205 all_retryable &= kind == ErrorKind::kRetryableValidationFailed;
206 error_msg +=
" - " + message +
"\n";
209 return RetryableValidationFailed(
"{}", error_msg);
211 return ValidationFailed(
"{}", error_msg);
223 [[nodiscard]]
const std::vector<Error>&
errors()
const {
return errors_; }
226 void RecordError(
Error err) { errors_.push_back(std::move(err)); }
229 std::vector<Error> errors_;
Base class for collecting errors in the builder pattern.
Definition error_collector.h:99
const std::vector< Error > & errors() const
Get read-only access to all collected errors.
Definition error_collector.h:223
Status CheckErrors() const
Check for accumulated errors and return them if any exist.
Definition error_collector.h:200
void ClearErrors()
Clear all accumulated errors.
Definition error_collector.h:220
auto & AddError(this auto &self, ::iceberg::unexpected< Error > err)
Add an unexpected result's error.
Definition error_collector.h:171
auto & AddError(this auto &self, ErrorKind kind, const std::format_string< Args... > fmt, Args &&... args)
Add a specific error.
Definition error_collector.h:126
auto & AddError(this auto &self, Error err)
Add an existing error object.
Definition error_collector.h:148
bool has_errors() const
Check if any errors have been collected.
Definition error_collector.h:184
size_t error_count() const
Get the number of errors collected.
Definition error_collector.h:189
Definition expected.h:1199
Definition expected.h:246
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
ErrorKind
Error types for iceberg.
Definition result.h:36
Define Result, Status, and error helpers.
Error with a kind and a message.
Definition result.h:76