types.hpp: Add argument formatter to assert errors

This commit is contained in:
Elad Ashkenazi 2024-08-01 09:00:51 +03:00
parent f64c912d02
commit c5c51ec0c1
2 changed files with 62 additions and 8 deletions

View file

@ -591,10 +591,42 @@ void fmt_class_string<std::source_location>::format(std::string& out, u64 arg)
namespace fmt
{
[[noreturn]] void raw_verify_error(std::source_location loc, const char8_t* msg)
[[noreturn]] void raw_verify_error(std::source_location loc, const char8_t* msg, usz object)
{
std::string out;
fmt::append(out, "%s%s", msg ? msg : u8"Verification failed", loc);
fmt::append(out, "%s (object: 0x%x)%s", msg ? msg : u8"Verification failed", object, loc);
thread_ctrl::emergency_exit(out);
}
[[noreturn]] void raw_range_error(std::source_location loc, std::string_view index, usz container_size)
{
std::string out;
if (container_size != umax)
{
fmt::append(out, "Range check failed (index: %s, container_size: %u)%s", index, container_size, loc);
}
else
{
fmt::append(out, "Range check failed (index: %s)%s", index, loc);
}
thread_ctrl::emergency_exit(out);
}
[[noreturn]] void raw_range_error(std::source_location loc, usz index, usz container_size)
{
std::string out;
if (container_size != umax)
{
fmt::append(out, "Range check failed (index: %u, container_size: %u)%s", index, container_size, loc);
}
else
{
fmt::append(out, "Range check failed (index: %u)%s", index, loc);
}
thread_ctrl::emergency_exit(out);
}