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::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

Public Member Functions

 ErrorCollector (ErrorCollector &&)=default
 
ErrorCollectoroperator= (ErrorCollector &&)=default
 
 ErrorCollector (const ErrorCollector &)=default
 
ErrorCollectoroperator= (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 and return reference to derived class.
 
auto & AddError (this auto &self, Error err)
 Add an existing error object and return reference to derived class.
 
auto & AddError (this auto &self, std::unexpected< Error > err)
 Add an unexpected result's error and return reference to derived class.
 
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< Errorerrors_
 

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) {
return AddError(ErrorKind::kInvalidArgument, "Value must be non-negative");
}
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:93

Member Function Documentation

◆ AddError() [1/3]

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

Add an existing error object and return reference to derived class.

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

Parameters
selfDeduced reference to the derived class instance
errThe error to add
Returns
Reference to the derived class for method chaining

◆ AddError() [2/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 and return reference to derived class.

Parameters
selfDeduced reference to the derived class instance
kindThe kind of error
fmtThe format string
argsThe arguments to format the message
Returns
Reference to the derived class for method chaining

◆ AddError() [3/3]

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

Add an unexpected result's error and return reference to derived class.

Useful for cases like below:

return AddError(InvalidArgument("Invalid value: {}", value));
auto & AddError(this auto &self, ErrorKind kind, const std::format_string< Args... > fmt, Args &&... args)
Add a specific error and return reference to derived class.
Definition error_collector.h:112
Parameters
selfDeduced reference to the derived class instance
errThe unexpected result containing the error to add
Returns
Reference to the derived class for method chaining

◆ 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, or a ValidationFailed error with all accumulated error messages

◆ 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: