diff --git a/AK/Error.h b/AK/Error.h index 831b2c2fb31..f57bb1266b2 100644 --- a/AK/Error.h +++ b/AK/Error.h @@ -15,6 +15,7 @@ # include #else # include +# include #endif namespace AK { diff --git a/AK/Format.h b/AK/Format.h index 36221884d9f..3d4f33bc6af 100644 --- a/AK/Format.h +++ b/AK/Format.h @@ -18,6 +18,7 @@ #ifndef KERNEL # include +# include #endif namespace AK { @@ -618,9 +619,18 @@ template<> struct Formatter : Formatter { ErrorOr format(FormatBuilder& builder, Error const& error) { +#if defined(__serenity__) && defined(KERNEL) if (error.is_errno()) return Formatter::format(builder, "Error(errno={})", error.code()); return Formatter::format(builder, "Error({})", error.string_literal()); +#else + if (error.is_syscall()) + return Formatter::format(builder, "{}: {} (errno={})", error.string_literal(), strerror(error.code()), error.code()); + if (error.is_errno()) + return Formatter::format(builder, "{} (errno={})", strerror(error.code()), error.code()); + + return Formatter::format(builder, "{}", error.string_literal()); +#endif } }; diff --git a/Userland/Libraries/LibMain/Main.cpp b/Userland/Libraries/LibMain/Main.cpp index 0324988dc48..e3d2bfdcb23 100644 --- a/Userland/Libraries/LibMain/Main.cpp +++ b/Userland/Libraries/LibMain/Main.cpp @@ -24,12 +24,7 @@ int main(int argc, char** argv) }); if (result.is_error()) { auto error = result.release_error(); - if (error.is_syscall()) - warnln("Runtime error: {}: {} (errno={})", error.string_literal(), strerror(error.code()), error.code()); - else if (error.is_errno()) - warnln("Runtime error: {} (errno={})", strerror(error.code()), error.code()); - else - warnln("Runtime error: {}", error.string_literal()); + warnln("Runtime error: {}", error); return 1; } return result.value();