iceberg-cpp
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
iceberg::ErrorCollector Class Reference

Base class for collecting errors in the builder pattern. More...

#include <error_collector.h>

Inheritance diagram for iceberg::ErrorCollector:
iceberg::ManifestGroup iceberg::MetadataScanBuilder iceberg::PendingUpdate iceberg::SnapshotManager iceberg::TableMetadataBuilder iceberg::TableScanBuilder< ScanType > iceberg::ExpireSnapshots iceberg::SetSnapshot iceberg::SnapshotUpdate iceberg::UpdateLocation iceberg::UpdatePartitionSpec iceberg::UpdatePartitionStatistics iceberg::UpdateProperties iceberg::UpdateSchema iceberg::UpdateSnapshotReference iceberg::UpdateSortOrder iceberg::UpdateStatistics iceberg::rest::RestIncrementalAppendScanBuilder iceberg::rest::RestTableScanBuilder

Public Member Functions

 ErrorCollector (ErrorCollector &&)=default
 
ErrorCollector & operator= (ErrorCollector &&)=default
 
 ErrorCollector (const ErrorCollector &)=default
 
ErrorCollector & operator= (const ErrorCollector &)=default
 
template<typename... Args>
auto & AddError (this auto &self, ErrorKind kind, const std::format_string< Args... > fmt, Args &&... args)
 Add a specific error.
 
auto & AddError (this auto &self, Error err)
 Add an existing error object.
 
auto & AddError (this auto &self, ::iceberg::unexpected< Error > err)
 Add an unexpected result's error.
 
auto & AddError (this auto &self, std::unexpected< Error > err)
 
bool has_errors () const
 Check if any errors have been collected.
 
size_t error_count () const
 Get the number of errors collected.
 
Status CheckErrors () const
 Check for accumulated errors and return them if any exist.
 
void ClearErrors ()
 Clear all accumulated errors.
 
const std::vector< Error > & errors () const
 Get read-only access to all collected errors.
 

Protected Attributes

std::vector< Error > errors_
 

Detailed Description

Base class for collecting errors in the builder pattern.

This class equips builders with error accumulation capabilities to make it easy for method chaining. Builder methods should call AddError() to accumulate errors and call CheckErrors() before completing the build process.

Example usage:

class MyBuilder : public ErrorCollector {
public:
MyBuilder& SetValue(int val) {
if (val < 0) {
AddError(ErrorKind::kInvalidArgument, "Value must be non-negative");
return *this;
}
value_ = val;
return *this;
}
Result<MyObject> Build() {
ICEBERG_RETURN_UNEXPECTED(CheckErrors());
return MyObject{value_};
}
private:
int value_ = 0;
};
Base class for collecting errors in the builder pattern.
Definition error_collector.h:99

Member Function Documentation

◆ AddError() [1/3]

auto & iceberg::ErrorCollector::AddError ( this auto &  self,
::iceberg::unexpected< Error >  err 
)
inline

Add an unexpected result's error.

Useful for cases like below:

AddError(InvalidArgument("Invalid value: {}", value));
return *this;
auto & AddError(this auto &self, ErrorKind kind, const std::format_string< Args... > fmt, Args &&... args)
Add a specific error.
Definition error_collector.h:126
Parameters
errThe unexpected result containing the error to add
Returns
Reference to the concrete derived builder in the default C++23 package, or ErrorCollector& in compatibility mode.

◆ AddError() [2/3]

auto & iceberg::ErrorCollector::AddError ( this auto &  self,
Error  err 
)
inline

Add an existing error object.

Useful when propagating errors from other components or reusing error objects without deconstructing and reconstructing them.

Parameters
errThe error to add
Returns
Reference to the concrete derived builder in the default C++23 package, or ErrorCollector& in compatibility mode.

◆ AddError() [3/3]

template<typename... Args>
auto & iceberg::ErrorCollector::AddError ( this auto &  self,
ErrorKind  kind,
const std::format_string< Args... >  fmt,
Args &&...  args 
)
inline

Add a specific error.

Parameters
kindThe kind of error
fmtThe format string
argsThe arguments to format the message
Returns
Reference to the concrete derived builder in the default C++23 package, or ErrorCollector& in compatibility mode.

◆ CheckErrors()

Status iceberg::ErrorCollector::CheckErrors ( ) const
inline

Check for accumulated errors and return them if any exist.

This should be called before completing a builder operation (e.g., in Build(), Apply(), or Commit() methods) to validate that no errors were accumulated during the builder method calls.

Returns
Status indicating success if no errors, a RetryableValidationFailed if all accumulated errors are retryable validations, or a ValidationFailed error with all accumulated error messages otherwise

◆ ClearErrors()

void iceberg::ErrorCollector::ClearErrors ( )
inline

Clear all accumulated errors.

This can be useful for resetting the error state in tests or when reusing a builder instance.

◆ error_count()

size_t iceberg::ErrorCollector::error_count ( ) const
inline

Get the number of errors collected.

Returns
The count of accumulated errors

◆ has_errors()

bool iceberg::ErrorCollector::has_errors ( ) const
inline

Check if any errors have been collected.

Returns
true if there are accumulated errors

The documentation for this class was generated from the following file: