diff options
| -rw-r--r-- | kernel/kapi/system.cpp | 4 | ||||
| -rw-r--r-- | libs/kstd/kstd/format.hpp | 1 | ||||
| -rw-r--r-- | libs/kstd/kstd/system_error.hpp | 25 |
3 files changed, 28 insertions, 2 deletions
diff --git a/kernel/kapi/system.cpp b/kernel/kapi/system.cpp index 23dadd3a..629e5990 100644 --- a/kernel/kapi/system.cpp +++ b/kernel/kapi/system.cpp @@ -22,8 +22,8 @@ namespace kapi::system [[gnu::weak]] auto panic(std::string_view message, kstd::error_code error, std::source_location location) -> void { - kstd::println(kstd::print_sink::stderr, "[PANIC] in {} : {} ({}:{}) @ {}:{}", location.function_name(), message, - error.category().name(), error.message(), location.file_name(), location.line()); + kstd::println(kstd::print_sink::stderr, "[PANIC] in {} : {} ({}) @ {}:{}", location.function_name(), message, error, + location.file_name(), location.line()); cpu::halt(); } diff --git a/libs/kstd/kstd/format.hpp b/libs/kstd/kstd/format.hpp index 5ed798db..5d7f4ae6 100644 --- a/libs/kstd/kstd/format.hpp +++ b/libs/kstd/kstd/format.hpp @@ -5,6 +5,7 @@ #include <kstd/bits/format/arg.hpp> #include <kstd/bits/format/args.hpp> #include <kstd/bits/format/context.hpp> +#include <kstd/bits/format/error.hpp> #include <kstd/bits/format/formatter.hpp> #include <kstd/bits/format/formatter/bool.hpp> #include <kstd/bits/format/formatter/byte.hpp> diff --git a/libs/kstd/kstd/system_error.hpp b/libs/kstd/kstd/system_error.hpp index f971703b..08725609 100644 --- a/libs/kstd/kstd/system_error.hpp +++ b/libs/kstd/kstd/system_error.hpp @@ -1,6 +1,8 @@ #ifndef KSTD_SYSTEM_ERROR_HPP #define KSTD_SYSTEM_ERROR_HPP +#include <kstd/format.hpp> + #include <compare> #include <cstdint> #include <functional> @@ -472,6 +474,29 @@ namespace kstd return {static_cast<int>(value), generic_category()}; } + template<> + struct formatter<error_code> + { + constexpr auto parse(format_parse_context & context) -> format_parse_context::iterator + { + auto it = context.begin(); + if (it != context.end() && *it != '}') + { + bits::format::error("Invalid specifier for string_view."); + } + return it; + } + + auto format(error_code const & error, format_context & context) const -> void + { + context.push(error.category().name()); + context.push(':'); + formatter<int>{}.format(error.value(), context); + context.push(':'); + context.push(error.message()); + } + }; + } // namespace kstd #endif |
