From c099877c35c1ebee5598117c0d58e78314725cf1 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 6 Dec 2022 19:35:34 +0100 Subject: [PATCH] Remove unnecessary error propagation in Log.cpp Serial and TextConsole always succeed, no need to act as if they could fail --- kernel/src/Log.cpp | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/kernel/src/Log.cpp b/kernel/src/Log.cpp index 2dd3291b..e4079699 100644 --- a/kernel/src/Log.cpp +++ b/kernel/src/Log.cpp @@ -17,32 +17,29 @@ static constexpr u32 RED = 0xffff0000; static char log_level_letters[] = {'D', 'I', 'W', 'E'}; // D for debug, I for info, W for warning, E for error static const char* ansi_color_codes_per_log_level[] = {"37", "37", "33", "31"}; // 37 is white, 33 yellow, 31 red -static Result log_serial(LogLevel level, const char* format, va_list origin) +static void log_serial(LogLevel level, const char* format, va_list origin) { va_list ap; va_copy(ap, origin); - TRY(Serial::printf("\x1b[%sm%c\x1b[0m ", ansi_color_codes_per_log_level[(int)level], - log_level_letters[(int)level])); + Serial::printf("\x1b[%sm%c\x1b[0m ", ansi_color_codes_per_log_level[(int)level], log_level_letters[(int)level]); - TRY(Serial::printf("%4zu.%.3zu ", Timer::ticks(), Timer::ticks_ms() - (Timer::ticks() * 1000))); + Serial::printf("%4zu.%.3zu ", Timer::ticks(), Timer::ticks_ms() - (Timer::ticks() * 1000)); - TRY(cstyle_format( + cstyle_format( format, [](char c, void*) -> Result { Serial::putchar(c); return {}; }, - nullptr, ap)); + nullptr, ap); Serial::putchar('\n'); va_end(ap); - - return {}; } -static Result log_text_console(LogLevel level, const char* format, va_list origin) +static void log_text_console(LogLevel level, const char* format, va_list origin) { va_list ap; va_copy(ap, origin); @@ -58,13 +55,13 @@ static Result log_text_console(LogLevel level, const char* format, va_list else TextConsole::set_foreground(WHITE); - TRY(cstyle_format( + cstyle_format( format, [](char c, void*) -> Result { TextConsole::putchar(c); return {}; }, - nullptr, ap)); + nullptr, ap); TextConsole::putchar('\n'); @@ -73,16 +70,14 @@ static Result log_text_console(LogLevel level, const char* format, va_list TextConsole::set_foreground(original_foreground); va_end(ap); - - return {}; } Result vlog(LogLevel level, const char* format, va_list ap) { if (!g_debug_enabled && level == LogLevel::Debug) return {}; - if (g_serial_enabled) TRY(log_serial(level, format, ap)); - if (g_text_console_enabled) TRY(log_text_console(level, format, ap)); + if (g_serial_enabled) log_serial(level, format, ap); + if (g_text_console_enabled) log_text_console(level, format, ap); return {}; }