mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 08:37:35 +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:
parent
cc35bab143
commit
7e6341587b
7 changed files with 29 additions and 14 deletions
|
@ -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)
|
||||
|
|
|
@ -12,11 +12,16 @@
|
|||
#include <LibCrypto/ASN1/DER.h>
|
||||
#include <LibCrypto/ASN1/PEM.h>
|
||||
|
||||
namespace {
|
||||
static String s_error_string;
|
||||
}
|
||||
|
||||
namespace TLS {
|
||||
|
||||
#define ERROR_WITH_SCOPE(error) \
|
||||
do { \
|
||||
return Error::from_string_view(TRY(String::formatted("{}: {}", current_scope, error))); \
|
||||
#define ERROR_WITH_SCOPE(error) \
|
||||
do { \
|
||||
s_error_string = TRY(String::formatted("{}: {}", current_scope, error)); \
|
||||
return Error::from_string_view(s_error_string.bytes_as_string_view()); \
|
||||
} while (0)
|
||||
|
||||
#define ENTER_TYPED_SCOPE(tag_kind_name, scope) \
|
||||
|
@ -77,7 +82,7 @@ static ErrorOr<SupportedGroup> oid_to_curve(Vector<int> curve)
|
|||
else if (curve == curve_prime256)
|
||||
return SupportedGroup::SECP256R1;
|
||||
|
||||
return Error::from_string_view(TRY(String::formatted("Unknown curve oid {}", curve)));
|
||||
return Error::from_string_view("Unknown curve oid"sv);
|
||||
}
|
||||
|
||||
static ErrorOr<Crypto::UnsignedBigInteger> parse_version(Crypto::ASN1::Decoder& decoder, Vector<StringView> current_scope)
|
||||
|
|
|
@ -33,7 +33,7 @@ struct Context {
|
|||
|
||||
struct ValidationError : public Error {
|
||||
ValidationError(DeprecatedString error)
|
||||
: Error(Error::from_string_view(error))
|
||||
: Error(Error::from_string_view(error.view()))
|
||||
, error_string(move(error))
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue