|
iceberg-cpp
|
Base class for collecting errors in the builder pattern. More...
#include <error_collector.h>
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_ |
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:
|
inline |
Add an unexpected result's error.
Useful for cases like below:
| err | The unexpected result containing the error to add |
|
inline |
Add an existing error object.
Useful when propagating errors from other components or reusing error objects without deconstructing and reconstructing them.
| err | The error to add |
|
inline |
Add a specific error.
| kind | The kind of error |
| fmt | The format string |
| args | The arguments to format the message |
|
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.
|
inline |
Clear all accumulated errors.
This can be useful for resetting the error state in tests or when reusing a builder instance.
|
inline |
Get the number of errors collected.
|
inline |
Check if any errors have been collected.