|
Porytiles
|
Abstract interface for all error types used in ChainableResult error chains. More...
#include <error.hpp>
Public Member Functions | |
| virtual | ~Error ()=default |
| virtual std::vector< std::string > | details (const TextFormatter &formatter) const =0 |
| Returns a formatted multi-line string representation of the error. | |
| virtual std::string | join (const TextFormatter &formatter, const std::string &delimiter="\n") const |
| Joins the error details into a single string with a specified delimiter. | |
| virtual std::unique_ptr< Error > | clone () const =0 |
| Creates a polymorphic copy of this error. | |
Abstract interface for all error types used in ChainableResult error chains.
The Error interface defines the contract that all error types must implement to participate in ChainableResult error chains. This interface enables polymorphic error handling while maintaining type safety and proper ownership semantics through the clone pattern.
Error implementations should be immutable value types that capture all relevant context about a failure at a specific point in the application. The details() method allows errors to format their messages based on the output context (TTY vs non-TTY), while the clone() method enables proper copying of errors when building error chains.
All concrete error types used with ChainableResult must derive from this interface. This requirement is enforced at compile time through static_assert in ChainableResult's constructors.
|
virtualdefault |
|
pure virtual |
Creates a polymorphic copy of this error.
The clone pattern is necessary because ChainableResult stores errors as unique_ptr<Error>, and errors need to be copied when building error chains from const references. Each concrete error type must implement this method to return a new instance with the same state.
Implemented in porytiles2::ImageLoadError, and porytiles2::FormattableError.
|
pure virtual |
Returns a formatted multi-line string representation of the error.
This method generates a human-readable description of the error, potentially including ANSI formatting codes if the provided TextFormatter indicates TTY output is enabled. Implementations should provide clear, actionable error messages that help users understand what went wrong and potentially how to fix it.
The return value is a vector of strings, where each element represents one line of the error message. Single-line errors return a vector with one element, while multi-line errors can return multiple lines for richer diagnostics.
| formatter | The TextFormatter to use for conditional formatting based on TTY status |
Implemented in porytiles2::ImageLoadError, and porytiles2::FormattableError.
|
inlinevirtual |
Joins the error details into a single string with a specified delimiter.
This is a convenience method that calls details() and joins the resulting lines with the specified delimiter. This is particularly useful in test code where a single string representation of the error is needed for assertion messages.
| formatter | The TextFormatter to use for conditional formatting based on TTY status |
| delimiter | The string to use between lines (defaults to newline) |