mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 20:17:13 +02:00
AK+LibSystem+LibMain: Add Error::from_syscall() for syscall failures
This creates an error that contains the name of the syscall that failed. This allows error handlers to print out the name of the call if they want to. :^)
This commit is contained in:
Notes:
sideshowbarker
2024-07-18 00:52:47 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/4e530135d55
@@ -8,6 +8,7 @@
|
||||
#include <AK/StringView.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibMain/Main.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
@@ -22,7 +23,13 @@ int main(int argc, char** argv)
|
||||
.arguments = arguments.span(),
|
||||
});
|
||||
if (result.is_error()) {
|
||||
warnln("Runtime error: {}", result.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());
|
||||
return 1;
|
||||
}
|
||||
return result.value();
|
||||
|
||||
Reference in New Issue
Block a user