Porytiles
Loading...
Searching...
No Matches
porytiles2::Error Class Referenceabstract

Abstract interface for all error types used in ChainableResult error chains. More...

#include <error.hpp>

Inheritance diagram for porytiles2::Error:
[legend]

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< Errorclone () const =0
 Creates a polymorphic copy of this error.
 

Detailed Description

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.

Definition at line 26 of file error.hpp.

Constructor & Destructor Documentation

◆ ~Error()

virtual porytiles2::Error::~Error ( )
virtualdefault

Member Function Documentation

◆ clone()

virtual std::unique_ptr< Error > porytiles2::Error::clone ( ) const
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.

Returns
A unique_ptr to a newly allocated copy of this error

Implemented in porytiles2::ImageLoadError, and porytiles2::FormattableError.

◆ details()

virtual std::vector< std::string > porytiles2::Error::details ( const TextFormatter formatter) const
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.

Parameters
formatterThe TextFormatter to use for conditional formatting based on TTY status
Returns
A vector of formatted strings describing the error, with each element representing one line

Implemented in porytiles2::ImageLoadError, and porytiles2::FormattableError.

◆ join()

virtual std::string porytiles2::Error::join ( const TextFormatter formatter,
const std::string &  delimiter = "\n" 
) const
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.

Parameters
formatterThe TextFormatter to use for conditional formatting based on TTY status
delimiterThe string to use between lines (defaults to newline)
Returns
A single string with all error detail lines joined by the delimiter

Definition at line 59 of file error.hpp.


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