59 [[nodiscard]]
virtual std::string
join(
const TextFormatter &formatter,
const std::string &delimiter =
"\n")
const
61 const auto lines =
details(formatter);
67 for (std::size_t i = 0; i < lines.size(); ++i) {
86 [[nodiscard]]
virtual std::unique_ptr<Error>
clone()
const = 0;
142 text_.push_back(std::move(text));
159 if (!text.empty() || !params.empty()) {
160 text_.push_back(std::move(text));
161 params_.push_back(std::move(params));
184 template <
typename FirstParam,
typename... RestParams>
186 !std::is_same_v<std::decay_t<FirstParam>, std::vector<FormatParam>> &&
187 std::is_same_v<std::decay_t<FirstParam>,
FormatParam> &&
188 (std::is_same_v<std::decay_t<RestParams>,
FormatParam> && ...))
191 text_.push_back(std::move(text));
193 std::vector<FormatParam> line_params;
194 line_params.reserve(1 +
sizeof...(RestParams));
195 line_params.push_back(std::forward<FirstParam>(first));
196 (line_params.push_back(std::forward<RestParams>(rest)), ...);
197 params_.push_back(std::move(line_params));
225 explicit FormattableError(std::vector<std::string> lines, std::vector<std::vector<FormatParam>> params)
226 : text_{std::move(lines)}, params_{std::move(params)}
244 std::vector<std::string> result;
245 result.reserve(text_.size());
247 for (std::size_t i = 0; i < text_.size(); ++i) {
248 if (i < params_.size() && !params_[i].empty()) {
249 result.push_back(formatter.
format(text_[i], params_[i]));
252 result.push_back(text_[i]);
272 for (
const auto &line : text_) {
289 [[nodiscard]] std::unique_ptr<Error>
clone()
const override
291 return std::make_unique<FormattableError>(text_, params_);
295 std::vector<std::string> text_;
296 std::vector<std::vector<FormatParam>> params_;
Abstract interface for all error types used in ChainableResult error chains.
virtual std::unique_ptr< Error > clone() const =0
Creates a polymorphic copy of this 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::vector< std::string > details(const TextFormatter &formatter) const =0
Returns a formatted multi-line string representation of the error.
Abstract base class for applying text styling with context-aware formatting.
virtual std::string format(const std::string &format_str, const std::vector< FormatParam > ¶ms) const
Formats a string with styled parameters using fmtlib syntax.