1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-07 21:17:07 +09:00

AK: Remove Error::from_string_view_or_print_error_and_return_errno

This was for use within Serenity's kernel. In Ladybird, it is just some
indirection to Error::from_string_view.
This commit is contained in:
Timothy Flynn 2025-05-10 16:12:27 -04:00 committed by Tim Flynn
parent e2b863ed3f
commit 4f132b9e40
Notes: github-actions[bot] 2025-05-11 01:21:22 +00:00
6 changed files with 13 additions and 24 deletions

View file

@ -17,11 +17,6 @@
namespace AK {
Error Error::from_string_view_or_print_error_and_return_errno(StringView string_literal, [[maybe_unused]] int code)
{
return Error::from_string_view(string_literal);
}
#ifdef AK_OS_WINDOWS
Error Error::from_windows_error(u32 windows_error)
{

View file

@ -36,12 +36,6 @@ public:
static Error from_windows_error();
#endif
// NOTE: For calling this method from within kernel code, we will simply print
// the error message and return the errno code.
// For calling this method from userspace programs, we will simply return from
// the Error::from_string_view method!
static Error from_string_view_or_print_error_and_return_errno(StringView string_literal, int code);
static Error from_syscall(StringView syscall_name, int rc)
{
return Error(syscall_name, rc);

View file

@ -15,18 +15,18 @@ namespace AK {
ErrorOr<ByteBuffer> decode_hex(StringView input)
{
if ((input.length() % 2) != 0)
return Error::from_string_view_or_print_error_and_return_errno("Hex string was not an even length"sv, EINVAL);
return Error::from_string_literal("Hex string was not an even length");
auto output = TRY(ByteBuffer::create_zeroed(input.length() / 2));
for (size_t i = 0; i < input.length() / 2; ++i) {
auto const c1 = decode_hex_digit(input[i * 2]);
if (c1 >= 16)
return Error::from_string_view_or_print_error_and_return_errno("Hex string contains invalid digit"sv, EINVAL);
return Error::from_string_literal("Hex string contains invalid digit");
auto const c2 = decode_hex_digit(input[i * 2 + 1]);
if (c2 >= 16)
return Error::from_string_view_or_print_error_and_return_errno("Hex string contains invalid digit"sv, EINVAL);
return Error::from_string_literal("Hex string contains invalid digit");
output[i] = (c1 << 4) + c2;
}

View file

@ -58,7 +58,7 @@ ErrorOr<Bytes> FixedMemoryStream::read_some(Bytes bytes)
ErrorOr<void> FixedMemoryStream::read_until_filled(AK::Bytes bytes)
{
if (remaining() < bytes.size())
return Error::from_string_view_or_print_error_and_return_errno("Can't read past the end of the stream memory"sv, EINVAL);
return Error::from_string_literal("Can't read past the end of the stream memory");
m_bytes.slice(m_offset).copy_trimmed_to(bytes);
m_offset += bytes.size();
@ -71,19 +71,19 @@ ErrorOr<size_t> FixedMemoryStream::seek(i64 offset, SeekMode seek_mode)
switch (seek_mode) {
case SeekMode::SetPosition:
if (offset > static_cast<i64>(m_bytes.size()))
return Error::from_string_view_or_print_error_and_return_errno("Offset past the end of the stream memory"sv, EINVAL);
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_view_or_print_error_and_return_errno("Offset past the end of the stream memory"sv, EINVAL);
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_view_or_print_error_and_return_errno("Offset past the start of the stream memory"sv, EINVAL);
return Error::from_string_literal("Offset past the start of the stream memory");
m_offset = m_bytes.size() + offset;
break;
@ -108,7 +108,7 @@ ErrorOr<size_t> FixedMemoryStream::write_some(ReadonlyBytes bytes)
ErrorOr<void> FixedMemoryStream::write_until_depleted(ReadonlyBytes bytes)
{
if (remaining() < bytes.size())
return Error::from_string_view_or_print_error_and_return_errno("Write of entire buffer ends past the memory area"sv, EINVAL);
return Error::from_string_literal("Write of entire buffer ends past the memory area");
TRY(write_some(bytes));
return {};
@ -185,7 +185,7 @@ ErrorOr<void> AllocatingMemoryStream::discard(size_t count)
VERIFY(m_write_offset >= m_read_offset);
if (count > used_buffer_size())
return Error::from_string_view_or_print_error_and_return_errno("Number of discarded bytes is higher than the number of allocated bytes"sv, EINVAL);
return Error::from_string_literal("Number of discarded bytes is higher than the number of allocated bytes");
m_read_offset += count;

View file

@ -50,7 +50,7 @@ public:
{
if constexpr (!IsConst<T>) {
if (!m_writing_enabled)
return Error::from_string_view_or_print_error_and_return_errno("Tried to obtain a non-const reference from a read-only FixedMemoryStream"sv, EINVAL);
return Error::from_string_literal("Tried to obtain a non-const reference from a read-only FixedMemoryStream");
}
T* value = reinterpret_cast<T*>(m_bytes.offset_pointer(m_offset));
@ -66,7 +66,7 @@ public:
{
if constexpr (!IsConst<T>) {
if (!m_writing_enabled)
return Error::from_string_view_or_print_error_and_return_errno("Tried to obtain a non-const span from a read-only FixedMemoryStream"sv, EINVAL);
return Error::from_string_literal("Tried to obtain a non-const span from a read-only FixedMemoryStream");
}
Span<T> span { reinterpret_cast<T*>(m_bytes.offset_pointer(m_offset)), count };

View file

@ -17,7 +17,7 @@ ErrorOr<void> Stream::read_until_filled(Bytes buffer)
size_t nread = 0;
while (nread < buffer.size()) {
if (is_eof())
return Error::from_string_view_or_print_error_and_return_errno("Reached end-of-file before filling the entire buffer"sv, EIO);
return Error::from_string_literal("Reached end-of-file before filling the entire buffer");
auto result = read_some(buffer.slice(nread));
if (result.is_error()) {
@ -70,7 +70,7 @@ ErrorOr<void> Stream::discard(size_t discarded_bytes)
while (discarded_bytes > 0) {
if (is_eof())
return Error::from_string_view_or_print_error_and_return_errno("Reached end-of-file before reading all discarded bytes"sv, EIO);
return Error::from_string_literal("Reached end-of-file before reading all discarded bytes");
auto slice = TRY(read_some(buffer.span().slice(0, min(discarded_bytes, continuous_read_size))));
discarded_bytes -= slice.size();