1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

AK+Everywhere: Disallow Error::from_string_view(FooString)

That pattern seems to show up a lot in code written by people that
aren't intimately familiar with the lifetime model of Error and Strings.
This commit makes the compiler detect it and present a more helpful
diagnostic than "garbage string at runtime".
This commit is contained in:
Ali Mohammad Pur 2023-04-27 21:21:19 +03:30 committed by Andreas Kling
parent cc35bab143
commit 7e6341587b
7 changed files with 29 additions and 14 deletions

View file

@ -89,7 +89,7 @@ ErrorOr<void> JsonArrayModel::set(int row, Vector<JsonValue>&& fields)
VERIFY(fields.size() == m_fields.size());
if ((size_t)row >= m_array.size())
return Error::from_string_view(TRY(String::formatted("Row out of bounds: {} >= {}", row, m_array.size())));
return Error::from_string_view("Row out of bounds"sv);
JsonObject obj;
for (size_t i = 0; i < m_fields.size(); ++i) {
@ -106,7 +106,7 @@ ErrorOr<void> JsonArrayModel::set(int row, Vector<JsonValue>&& fields)
ErrorOr<void> JsonArrayModel::remove(int row)
{
if ((size_t)row >= m_array.size())
return Error::from_string_view(TRY(String::formatted("Row out of bounds: {} >= {}", row, m_array.size())));
return Error::from_string_view("Row out of bounds"sv);
JsonArray new_array;
for (size_t i = 0; i < m_array.size(); ++i)