|
Porytiles
|
General-purpose error implementation with formatted message support. More...
#include <error.hpp>
Public Member Functions | |
| FormattableError ()=default | |
| Constructs an empty FormattableError with no message. | |
| FormattableError (std::string text) | |
| Constructs a FormattableError with a plain text message. | |
| FormattableError (std::string text, std::vector< FormatParam > params) | |
| Constructs a FormattableError with a format string and styled parameters. | |
| template<typename FirstParam , typename... RestParams> requires ( !std::is_same_v<std::decay_t<FirstParam>, std::vector<FormatParam>> && std::is_same_v<std::decay_t<FirstParam>, FormatParam> && (std::is_same_v<std::decay_t<RestParams>, FormatParam> && ...)) | |
| FormattableError (std::string text, FirstParam &&first, RestParams &&...rest) | |
| Constructs a FormattableError with a format string and variadic styled parameters. | |
| FormattableError (std::vector< std::string > lines) | |
| Constructs a FormattableError with multiple plain text lines. | |
| FormattableError (std::vector< std::string > lines, std::vector< std::vector< FormatParam > > params) | |
| Constructs a FormattableError with multiple formatted lines. | |
| std::vector< std::string > | details (const TextFormatter &formatter) const override |
| Returns the formatted error message lines with appropriate styling. | |
| bool | has_details () const |
| Checks whether this FormattableError contains any message content. | |
| std::unique_ptr< Error > | clone () const override |
| Creates a polymorphic copy of this FormattableError. | |
Public Member Functions inherited from porytiles2::Error | |
| virtual | ~Error ()=default |
| 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. | |
General-purpose error implementation with formatted message support.
FormattableError is a concrete Error implementation designed for common error scenarios where creating a specialized error type would be unnecessary overhead. It supports both simple string messages and formatted messages with styled parameters using TextFormatter and FormatParam.
Key features:
Example usage:
When to use FormattableError vs specialized error types:
|
default |
Constructs an empty FormattableError with no message.
Creates a FormattableError with no text content. This is primarily used for error chain passthrough scenarios where the current layer doesn't need to add additional error context. Empty FormattableErrors can be detected using the has_details() method and are typically filtered out during error chain visualization.
|
inlineexplicit |
Constructs a FormattableError with a plain text message.
Creates a FormattableError containing a simple string message with no parameter formatting. This constructor is used for straightforward error messages that don't require styled parameters. The message is stored as a single-line error.
| text | The error message text |
|
inlineexplicit |
Constructs a FormattableError with a format string and styled parameters.
Creates a FormattableError that uses fmtlib-style formatting to substitute styled parameters into the message. The text parameter should contain {} placeholders that will be replaced with the styled text from the params vector when details() is called. The message is stored as a single-line error.
| text | The format string with {} placeholders |
| params | Vector of FormatParams to substitute into the format string |
|
inlineexplicit |
Constructs a FormattableError with a format string and variadic styled parameters.
Convenience constructor that allows passing FormatParams directly as arguments instead of wrapping them in a std::vector. This provides more natural syntax for error construction with a known number of parameters. The message is stored as a single-line error.
Example:
| FirstParam | Type of the first parameter |
| RestParams | Types of remaining parameters |
| text | The format string with {} placeholders |
| first | First FormatParam argument |
| rest | Remaining FormatParam arguments to substitute into the format string |
|
inlineexplicit |
Constructs a FormattableError with multiple plain text lines.
Creates a FormattableError containing multiple lines of text with no parameter formatting. This constructor is used for multi-line error messages that don't require styled parameters.
| lines | Vector of error message lines |
|
inlineexplicit |
Constructs a FormattableError with multiple formatted lines.
Creates a FormattableError with multiple lines, where each line can have its own styled parameters. The lines vector should contain format strings with {} placeholders, and the params vector should contain a corresponding vector of FormatParams for each line.
If params is shorter than lines, the extra lines will have no parameters. If params is longer than lines, the extra parameter vectors will be ignored.
| lines | Vector of format strings, one per line |
| params | Vector of parameter vectors, one per line |
|
inlineoverridevirtual |
Creates a polymorphic copy of this FormattableError.
Implements the Error clone pattern by creating a new FormattableError with the same text and parameters. This allows FormattableError instances to be copied when building ChainableResult error chains.
Implements porytiles2::Error.
|
inlineoverridevirtual |
Returns the formatted error message lines with appropriate styling.
Generates the error message lines by formatting each line independently. For lines without parameters, the plain text is returned. For lines with parameters, the text is formatted with styled parameters using the provided TextFormatter. The formatter determines whether to apply ANSI styling codes or return plain text based on the output context.
| formatter | The TextFormatter to use for applying styles |
Implements porytiles2::Error.
|
inline |
Checks whether this FormattableError contains any message content.
Returns true if the error contains at least one non-empty line, false otherwise. This method is used to distinguish between errors that carry meaningful information and empty errors created for passthrough purposes. Empty errors (created with the default constructor, empty string, or only empty lines) are typically filtered out during error chain visualization in UserDiagnostics::fatal().