mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-26 20:55:35 +03:00
AK+LibMain: Improve formatter for AK::Error in userspace
Print the full associated string metadata by default (if available.)
This commit is contained in:
parent
8877dd0eea
commit
452a5531be
Notes:
sideshowbarker
2024-07-17 22:33:03 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/452a5531bef
@ -15,6 +15,7 @@
|
||||
# include <LibC/errno_codes.h>
|
||||
#else
|
||||
# include <errno.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
namespace AK {
|
||||
|
10
AK/Format.h
10
AK/Format.h
@ -18,6 +18,7 @@
|
||||
|
||||
#ifndef KERNEL
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
namespace AK {
|
||||
@ -618,9 +619,18 @@ template<>
|
||||
struct Formatter<Error> : Formatter<FormatString> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Error const& error)
|
||||
{
|
||||
#if defined(__serenity__) && defined(KERNEL)
|
||||
if (error.is_errno())
|
||||
return Formatter<FormatString>::format(builder, "Error(errno={})", error.code());
|
||||
return Formatter<FormatString>::format(builder, "Error({})", error.string_literal());
|
||||
#else
|
||||
if (error.is_syscall())
|
||||
return Formatter<FormatString>::format(builder, "{}: {} (errno={})", error.string_literal(), strerror(error.code()), error.code());
|
||||
if (error.is_errno())
|
||||
return Formatter<FormatString>::format(builder, "{} (errno={})", strerror(error.code()), error.code());
|
||||
|
||||
return Formatter<FormatString>::format(builder, "{}", error.string_literal());
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user