mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:47:35 +00:00
Everywhere: Split Error::from_string_literal and Error::from_string_view
Error::from_string_literal now takes direct char const*s, while Error::from_string_view does what Error::from_string_literal used to do: taking StringViews. This change will remove the need to insert `sv` after error strings when returning string literal errors once StringView(char const*) is removed. No functional changes.
This commit is contained in:
parent
c70f45ff44
commit
e5f09ea170
51 changed files with 282 additions and 261 deletions
|
@ -73,14 +73,14 @@ ErrorOr<Account> Account::self([[maybe_unused]] Read options)
|
|||
|
||||
auto pwd = TRY(Core::System::getpwuid(getuid()));
|
||||
if (!pwd.has_value())
|
||||
return Error::from_string_literal("No such user"sv);
|
||||
return Error::from_string_literal("No such user");
|
||||
|
||||
spwd spwd = {};
|
||||
#ifndef AK_OS_BSD_GENERIC
|
||||
if (options != Read::PasswdOnly) {
|
||||
auto maybe_spwd = TRY(Core::System::getspnam({ pwd->pw_name, strlen(pwd->pw_name) }));
|
||||
if (!maybe_spwd.has_value())
|
||||
return Error::from_string_literal("No shadow entry for user"sv);
|
||||
return Error::from_string_literal("No shadow entry for user");
|
||||
spwd = maybe_spwd.release_value();
|
||||
}
|
||||
#endif
|
||||
|
@ -92,14 +92,14 @@ ErrorOr<Account> Account::from_name(char const* username, [[maybe_unused]] Read
|
|||
{
|
||||
auto pwd = TRY(Core::System::getpwnam({ username, strlen(username) }));
|
||||
if (!pwd.has_value())
|
||||
return Error::from_string_literal("No such user"sv);
|
||||
return Error::from_string_literal("No such user");
|
||||
|
||||
spwd spwd = {};
|
||||
#ifndef AK_OS_BSD_GENERIC
|
||||
if (options != Read::PasswdOnly) {
|
||||
auto maybe_spwd = TRY(Core::System::getspnam({ pwd->pw_name, strlen(pwd->pw_name) }));
|
||||
if (!maybe_spwd.has_value())
|
||||
return Error::from_string_literal("No shadow entry for user"sv);
|
||||
return Error::from_string_literal("No shadow entry for user");
|
||||
spwd = maybe_spwd.release_value();
|
||||
}
|
||||
#endif
|
||||
|
@ -110,14 +110,14 @@ ErrorOr<Account> Account::from_uid(uid_t uid, [[maybe_unused]] Read options)
|
|||
{
|
||||
auto pwd = TRY(Core::System::getpwuid(uid));
|
||||
if (!pwd.has_value())
|
||||
return Error::from_string_literal("No such user"sv);
|
||||
return Error::from_string_literal("No such user");
|
||||
|
||||
spwd spwd = {};
|
||||
#ifndef AK_OS_BSD_GENERIC
|
||||
if (options != Read::PasswdOnly) {
|
||||
auto maybe_spwd = TRY(Core::System::getspnam({ pwd->pw_name, strlen(pwd->pw_name) }));
|
||||
if (!maybe_spwd.has_value())
|
||||
return Error::from_string_literal("No shadow entry for user"sv);
|
||||
return Error::from_string_literal("No shadow entry for user");
|
||||
spwd = maybe_spwd.release_value();
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@ ErrorOr<CommandResult> command(String const& command_string, Optional<LexicalPat
|
|||
{
|
||||
auto parts = command_string.split(' ');
|
||||
if (parts.is_empty())
|
||||
return Error::from_string_literal("empty command"sv);
|
||||
return Error::from_string_literal("empty command");
|
||||
auto program = parts[0];
|
||||
parts.remove(0);
|
||||
return command(program, parts, chdir);
|
||||
|
|
|
@ -41,7 +41,7 @@ ErrorOr<FilePermissionsMask> FilePermissionsMask::from_numeric_notation(StringVi
|
|||
{
|
||||
mode_t mode = AK::StringUtils::convert_to_uint_from_octal<u16>(string).value_or(01000);
|
||||
if (mode > 0777)
|
||||
return Error::from_string_literal("invalid octal representation"sv);
|
||||
return Error::from_string_literal("invalid octal representation");
|
||||
return FilePermissionsMask().assign_permissions(mode);
|
||||
}
|
||||
|
||||
|
@ -73,9 +73,9 @@ ErrorOr<FilePermissionsMask> FilePermissionsMask::from_symbolic_notation(StringV
|
|||
else if (ch == '=')
|
||||
operation = Operation::Assign;
|
||||
else if (classes == 0)
|
||||
return Error::from_string_literal("invalid class: expected 'u', 'g', 'o' or 'a'"sv);
|
||||
return Error::from_string_literal("invalid class: expected 'u', 'g', 'o' or 'a'");
|
||||
else
|
||||
return Error::from_string_literal("invalid operation: expected '+', '-' or '='"sv);
|
||||
return Error::from_string_literal("invalid operation: expected '+', '-' or '='");
|
||||
|
||||
// if an operation was specified without a class, assume all
|
||||
if (classes == 0)
|
||||
|
@ -106,7 +106,7 @@ ErrorOr<FilePermissionsMask> FilePermissionsMask::from_symbolic_notation(StringV
|
|||
else if (ch == 'x')
|
||||
write_bits = 1;
|
||||
else
|
||||
return Error::from_string_literal("invalid symbolic permission: expected 'r', 'w' or 'x'"sv);
|
||||
return Error::from_string_literal("invalid symbolic permission: expected 'r', 'w' or 'x'");
|
||||
|
||||
mode_t clear_bits = operation == Operation::Assign ? 7 : write_bits;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ LocalServer::~LocalServer()
|
|||
ErrorOr<void> LocalServer::take_over_from_system_server(String const& socket_path)
|
||||
{
|
||||
if (m_listening)
|
||||
return Error::from_string_literal("Core::LocalServer: Can't perform socket takeover when already listening"sv);
|
||||
return Error::from_string_literal("Core::LocalServer: Can't perform socket takeover when already listening");
|
||||
|
||||
auto socket = TRY(take_over_socket_from_system_server(socket_path));
|
||||
m_fd = TRY(socket->release_fd());
|
||||
|
|
|
@ -45,19 +45,19 @@ public:
|
|||
switch (seek_mode) {
|
||||
case SeekMode::SetPosition:
|
||||
if (offset >= static_cast<i64>(m_bytes.size()))
|
||||
return Error::from_string_literal("Offset past the end of the stream memory"sv);
|
||||
return Error::from_string_literal("Offset past the end of the stream memory");
|
||||
|
||||
m_offset = offset;
|
||||
break;
|
||||
case SeekMode::FromCurrentPosition:
|
||||
if (offset + static_cast<i64>(m_offset) >= static_cast<i64>(m_bytes.size()))
|
||||
return Error::from_string_literal("Offset past the end of the stream memory"sv);
|
||||
return Error::from_string_literal("Offset past the end of the stream memory");
|
||||
|
||||
m_offset += offset;
|
||||
break;
|
||||
case SeekMode::FromEndPosition:
|
||||
if (offset >= static_cast<i64>(m_bytes.size()))
|
||||
return Error::from_string_literal("Offset past the start of the stream memory"sv);
|
||||
return Error::from_string_literal("Offset past the start of the stream memory");
|
||||
|
||||
m_offset = m_bytes.size() - offset;
|
||||
break;
|
||||
|
|
|
@ -277,7 +277,7 @@ ErrorOr<NonnullOwnPtr<SOCKSProxyClient>> SOCKSProxyClient::connect(Socket& under
|
|||
auto reply = TRY(send_connect_request_message(underlying, version, target, target_port, command));
|
||||
if (reply != Reply::Succeeded) {
|
||||
underlying.close();
|
||||
return Error::from_string_literal(reply_response_name(reply));
|
||||
return Error::from_string_view(reply_response_name(reply));
|
||||
}
|
||||
|
||||
return adopt_nonnull_own_or_enomem(new SOCKSProxyClient {
|
||||
|
@ -296,7 +296,7 @@ ErrorOr<NonnullOwnPtr<SOCKSProxyClient>> SOCKSProxyClient::connect(Socket& under
|
|||
auto reply = TRY(send_connect_request_message(underlying, version, target, target_port, command));
|
||||
if (reply != Reply::Succeeded) {
|
||||
underlying.close();
|
||||
return Error::from_string_literal(reply_response_name(reply));
|
||||
return Error::from_string_view(reply_response_name(reply));
|
||||
}
|
||||
|
||||
return adopt_nonnull_own_or_enomem(new SOCKSProxyClient {
|
||||
|
|
|
@ -118,7 +118,7 @@ public:
|
|||
if (!result.is_error())
|
||||
break;
|
||||
if (result.error() != QueueStatus::Full)
|
||||
return Error::from_string_literal("Unexpected error while enqueuing"sv);
|
||||
return Error::from_string_literal("Unexpected error while enqueuing");
|
||||
|
||||
wait_function();
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ private:
|
|||
SharedMemorySPCQ* shared_queue = is_new ? new (raw_mapping) SharedMemorySPCQ() : reinterpret_cast<SharedMemorySPCQ*>(raw_mapping);
|
||||
|
||||
if (!shared_queue)
|
||||
return Error::from_string_literal("Unexpected error when creating shared queue from raw memory"sv);
|
||||
return Error::from_string_literal("Unexpected error when creating shared queue from raw memory");
|
||||
|
||||
return SharedSingleProducerCircularQueue<T, Size> { move(name), adopt_ref(*new (nothrow) RefCountedSharedMemorySPCQ(shared_queue, fd)) };
|
||||
}
|
||||
|
|
|
@ -336,7 +336,8 @@ ErrorOr<IPv4Address> Socket::resolve_host(String const& host, SocketType type)
|
|||
return Error::from_syscall("getaddrinfo", -errno);
|
||||
}
|
||||
|
||||
return Error::from_string_literal(gai_strerror(rc));
|
||||
auto const* error_string = gai_strerror(rc);
|
||||
return Error::from_string_view({ error_string, strlen(error_string) });
|
||||
}
|
||||
|
||||
auto* socket_address = bit_cast<struct sockaddr_in*>(results->ai_addr);
|
||||
|
|
|
@ -47,7 +47,7 @@ ErrorOr<NonnullOwnPtr<Core::Stream::LocalSocket>> take_over_socket_from_system_s
|
|||
} else {
|
||||
auto it = s_overtaken_sockets.find(socket_path);
|
||||
if (it == s_overtaken_sockets.end())
|
||||
return Error::from_string_literal("Non-existent socket requested"sv);
|
||||
return Error::from_string_literal("Non-existent socket requested");
|
||||
fd = it->value;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ ErrorOr<NonnullOwnPtr<Core::Stream::LocalSocket>> take_over_socket_from_system_s
|
|||
auto stat = TRY(Core::System::fstat(fd));
|
||||
|
||||
if (!S_ISSOCK(stat.st_mode))
|
||||
return Error::from_string_literal("The fd we got from SystemServer is not a socket"sv);
|
||||
return Error::from_string_literal("The fd we got from SystemServer is not a socket");
|
||||
|
||||
auto socket = TRY(Core::Stream::LocalSocket::adopt_fd(fd));
|
||||
// It had to be !CLOEXEC for obvious reasons, but we
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue