50 template<
typename Fmt,
typename... Args>
51 error(Fmt
const &fmt, Args &&... args)
noexcept {
52 if constexpr (
sizeof...(args) == 0) {
55 _message = fmt::format(fmt, std::forward<Args>(args)...);
60 virtual std::string error_info_string()
const noexcept = 0;
65 return tag_name(tag());
69 return fmt::format(
"{}: {}. {}",
76 [[nodiscard]]
std::string message() const noexcept {
80 error &caused_by(error
const &other)
noexcept {
81 _message = fmt::format(
"{}\nCaused by: {}", _message, other.string());
89 template<
typename InfoTag,
typename InfoValueType>
90 error &
set(InfoValueType &&info_value)
noexcept {
95 if (location.has_file()) {
96 set<url_tag>(location.file());
98 set<line_tag>(location.line());
99 set<column_tag>(location.column());
107 ttlet line =
static_cast<int>(get<line_tag>());
108 ttlet column =
static_cast<int>(get<column_tag>());
111 if (has<url_tag>()) {
112 ttlet url =
static_cast<URL>(get<url_tag>());
113 expression_location.set_file(
std::move(url));
116 statement_location += expression_location;
118 if (statement_location.has_file()) {
119 set<url_tag>(statement_location.file());
121 set<line_tag>(statement_location.line());
122 set<column_tag>(statement_location.column());
127 template<
typename InfoTag>
128 datum &get() noexcept {
132 template<
typename InfoTag>
133 datum
const &get() const noexcept {
137 template<
typename InfoTag>
138 bool has() const noexcept {
147 return os << to_string(rhs);
158 if (error_info.has(info_tag) == 1) {
159 error_info.get(info_tag) = info_value;
167 if (error_info.has(info_tag) == 1) {
168 error_info.get(info_tag) =
std::move(info_value);
176 tt_assert(error_info.has(info_tag) == 1);
177 return error_info.get(info_tag);
181 tt_assert(error_info.has(info_tag) == 1);
182 return error_info.get(info_tag);
186 if (error_info.has(info_tag) == 0) {
189 return !error_info.get(info_tag).is_undefined();
199 template<
typename Fmt,
typename... Args>
200 sub_error(Fmt
const &fmt, Args &&... args) noexcept :
201 error(fmt, std::forward<Args>(args)...) {}
204 _message = fmt::format(
"{}\nCaused by: {}", _message, other.string());
212 template<
typename InfoTag,
typename InfoValueType>
214 static_assert(has_tag<InfoTag,InfoTags...>(),
"Unknown tag of error info value.");
215 error_info.template get<InfoTag>() = std::forward<InfoValueType>(info_value);
220 if (location.has_file()) {
221 set<url_tag>(location.file());
223 set<line_tag>(location.line());
224 set<column_tag>(location.column());
228 template<
typename InfoTag>
229 datum &get() noexcept {
230 static_assert(has_tag<InfoTag,InfoTags...>(),
"Unknown tag of error info value.");
231 return error_info.template get<InfoTag>();
234 template<
typename InfoTag>
235 datum
const &get() const noexcept {
236 static_assert(has_tag<InfoTag,InfoTags...>(),
"Unknown tag of error info value.");
237 return error_info.template get<InfoTag>();
240 template<
typename InfoTag>
241 bool has() const noexcept {
242 static_assert(has_tag<InfoTag,InfoTags...>(),
"Unknown tag of error info value.");
243 return !((error_info.template get<InfoTag>()).is_undefined());
246 sub_error &log(
char const *source_file,
int source_line) {
247 logger.log<log_level::Exception>(cpu_counter_clock::now(),
"{}", *
this, source_code_ptr(source_file, source_line));
248 increment_counter<Tag>();
252 std::string error_info_string() const noexcept
override {
255 for (
size_t i = 0; i < error_info.size(); i++) {
260 r += fmt::format(
"{}={}",
261 tag_name(error_info.get_tag(i)),