mirror of
https://github.com/status-im/realm-js.git
synced 2025-01-11 06:46:03 +00:00
Change the API-misuse exceptions from runtime_error to logic_error
This commit is contained in:
parent
11018952e9
commit
847b6852c9
@ -64,7 +64,7 @@ class TransactLogValidationMixin {
|
||||
REALM_NOINLINE
|
||||
void schema_error()
|
||||
{
|
||||
throw std::runtime_error("Schema mismatch detected: another process has modified the Realm file's schema in an incompatible way");
|
||||
throw std::logic_error("Schema mismatch detected: another process has modified the Realm file's schema in an incompatible way");
|
||||
}
|
||||
|
||||
// Throw an exception if the currently modified table already existed before
|
||||
|
@ -87,7 +87,7 @@ bool List::is_valid() const
|
||||
void List::verify_attached() const
|
||||
{
|
||||
if (!is_valid()) {
|
||||
throw InvalidatedException{};
|
||||
throw InvalidatedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,8 +95,8 @@ public:
|
||||
// The List object has been invalidated (due to the Realm being invalidated,
|
||||
// or the containing object being deleted)
|
||||
// All non-noexcept functions can throw this
|
||||
struct InvalidatedException : public std::runtime_error {
|
||||
InvalidatedException() : std::runtime_error("Access to invalidated List object") {}
|
||||
struct InvalidatedException : public std::logic_error {
|
||||
InvalidatedException() : std::logic_error("Access to invalidated List object") {}
|
||||
};
|
||||
|
||||
// The input index parameter was out of bounds
|
||||
|
@ -47,7 +47,7 @@ T stot(std::string const& s) {
|
||||
// check a precondition and throw an exception if it is not met
|
||||
// this should be used iff the condition being false indicates a bug in the caller
|
||||
// of the function checking its preconditions
|
||||
#define precondition(condition, message) if (!__builtin_expect(condition, 1)) { throw std::runtime_error(message); }
|
||||
#define precondition(condition, message) if (!__builtin_expect(condition, 1)) { throw std::logic_error(message); }
|
||||
|
||||
// FIXME: TrueExpression and FalseExpression should be supported by core in some way
|
||||
struct TrueExpression : realm::Expression {
|
||||
@ -150,7 +150,7 @@ void add_numeric_constraint_to_query(Query& query,
|
||||
query.and_query(lhs != rhs);
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported operator for numeric queries.");
|
||||
throw std::logic_error("Unsupported operator for numeric queries.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ void add_bool_constraint_to_query(Query &query, Predicate::Operator operatorType
|
||||
query.and_query(lhs != rhs);
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported operator for numeric queries.");
|
||||
throw std::logic_error("Unsupported operator for numeric queries.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ void add_string_constraint_to_query(Query &query,
|
||||
query.and_query(column.not_equal(value, case_sensitive));
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported operator for string queries.");
|
||||
throw std::logic_error("Unsupported operator for string queries.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -207,7 +207,7 @@ void add_string_constraint_to_query(realm::Query &query,
|
||||
query.and_query(column.not_equal(value, case_sensitive));
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Substring comparison not supported for keypath substrings.");
|
||||
throw std::logic_error("Substring comparison not supported for keypath substrings.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ void add_binary_constraint_to_query(Query &query,
|
||||
query.not_equal(column.m_column, BinaryData(value));
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Unsupported operator for binary queries.");
|
||||
throw std::logic_error("Unsupported operator for binary queries.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,7 +248,7 @@ void add_binary_constraint_to_query(realm::Query &query,
|
||||
query.not_equal(column.m_column, BinaryData(value));
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Substring comparison not supported for keypath substrings.");
|
||||
throw std::logic_error("Substring comparison not supported for keypath substrings.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,7 +267,7 @@ void add_link_constraint_to_query(realm::Query &query,
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw std::runtime_error("Only 'equal' and 'not equal' operators supported for object comparison.");
|
||||
throw std::logic_error("Only 'equal' and 'not equal' operators supported for object comparison.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,7 +298,7 @@ struct ValueGetter<Timestamp, TableGetter> {
|
||||
static Timestamp convert(TableGetter&&, const parser::Expression & value, Arguments &args)
|
||||
{
|
||||
if (value.type != parser::Expression::Type::Argument) {
|
||||
throw std::runtime_error("You must pass in a date argument to compare");
|
||||
throw std::logic_error("You must pass in a date argument to compare");
|
||||
}
|
||||
return args.timestamp_for_argument(stot<int>(value.s));
|
||||
}
|
||||
@ -312,7 +312,7 @@ struct ValueGetter<bool, TableGetter> {
|
||||
return args.bool_for_argument(stot<int>(value.s));
|
||||
}
|
||||
if (value.type != parser::Expression::Type::True && value.type != parser::Expression::Type::False) {
|
||||
throw std::runtime_error("Attempting to compare bool property to a non-bool value");
|
||||
throw std::logic_error("Attempting to compare bool property to a non-bool value");
|
||||
}
|
||||
return value.type == parser::Expression::Type::True;
|
||||
}
|
||||
@ -359,7 +359,7 @@ struct ValueGetter<String, TableGetter> {
|
||||
return args.string_for_argument(stot<int>(value.s));
|
||||
}
|
||||
if (value.type != parser::Expression::Type::String) {
|
||||
throw std::runtime_error("Attempting to compare String property to a non-String value");
|
||||
throw std::logic_error("Attempting to compare String property to a non-String value");
|
||||
}
|
||||
return value.s;
|
||||
}
|
||||
@ -372,7 +372,7 @@ struct ValueGetter<Binary, TableGetter> {
|
||||
if (value.type == parser::Expression::Type::Argument) {
|
||||
return args.binary_for_argument(stot<int>(value.s));
|
||||
}
|
||||
throw std::runtime_error("Binary properties must be compared against a binary argument.");
|
||||
throw std::logic_error("Binary properties must be compared against a binary argument.");
|
||||
}
|
||||
};
|
||||
|
||||
@ -423,7 +423,7 @@ void do_add_comparison_to_query(Query &query, Predicate::Comparison cmp,
|
||||
add_link_constraint_to_query(query, cmp.op, expr, link_argument(lhs, rhs, args));
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error(util::format("Object type '%1' not supported", string_for_property_type(type)));
|
||||
throw std::logic_error(util::format("Object type '%1' not supported", string_for_property_type(type)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -439,7 +439,7 @@ void do_add_null_comparison_to_query(Query &query, Predicate::Operator op, const
|
||||
query.and_query(column == realm::null());
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Only 'equal' and 'not equal' operators supported when comparing against 'null'.");
|
||||
throw std::logic_error("Only 'equal' and 'not equal' operators supported when comparing against 'null'.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -456,7 +456,7 @@ void do_add_null_comparison_to_query<Binary>(Query &query, Predicate::Operator o
|
||||
query.equal(expr.prop->table_column, realm::null());
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Only 'equal' and 'not equal' operators supported when comparing against 'null'.");
|
||||
throw std::logic_error("Only 'equal' and 'not equal' operators supported when comparing against 'null'.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -472,7 +472,7 @@ void do_add_null_comparison_to_query<Link>(Query &query, Predicate::Operator op,
|
||||
query.and_query(query.get_table()->column<Link>(expr.prop->table_column).is_null());
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("Only 'equal' and 'not equal' operators supported for object comparison.");
|
||||
throw std::logic_error("Only 'equal' and 'not equal' operators supported for object comparison.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -505,9 +505,9 @@ void do_add_null_comparison_to_query(Query &query, Predicate::Comparison cmp, co
|
||||
do_add_null_comparison_to_query<Link>(query, cmp.op, expr);
|
||||
break;
|
||||
case realm::PropertyType::Array:
|
||||
throw std::runtime_error("Comparing Lists to 'null' is not supported");
|
||||
throw std::logic_error("Comparing Lists to 'null' is not supported");
|
||||
default:
|
||||
throw std::runtime_error(util::format("Object type '%1' not supported", string_for_property_type(type)));
|
||||
throw std::logic_error(util::format("Object type '%1' not supported", string_for_property_type(type)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -545,7 +545,7 @@ void add_comparison_to_query(Query &query, const Predicate &pred, Arguments &arg
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Predicate expressions must compare a keypath and another keypath or a constant value");
|
||||
throw std::logic_error("Predicate expressions must compare a keypath and another keypath or a constant value");
|
||||
}
|
||||
}
|
||||
|
||||
@ -592,7 +592,7 @@ void update_query_with_predicate(Query &query, const Predicate &pred, Arguments
|
||||
break;
|
||||
|
||||
default:
|
||||
throw std::runtime_error("Invalid predicate type");
|
||||
throw std::logic_error("Invalid predicate type");
|
||||
}
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
@ -604,7 +604,7 @@ Results::OutOfBoundsIndexException::OutOfBoundsIndexException(size_t r, size_t c
|
||||
, requested(r), valid_count(c) {}
|
||||
|
||||
Results::UnsupportedColumnTypeException::UnsupportedColumnTypeException(size_t column, const Table* table, const char* operation)
|
||||
: std::runtime_error(util::format("Cannot %1 property '%2': operation not supported for '%3' properties",
|
||||
: std::logic_error(util::format("Cannot %1 property '%2': operation not supported for '%3' properties",
|
||||
operation, table->get_column_name(column),
|
||||
string_for_property_type(static_cast<PropertyType>(table->get_column_type(column)))))
|
||||
, column_index(column)
|
||||
|
@ -141,8 +141,8 @@ public:
|
||||
|
||||
// The Results object has been invalidated (due to the Realm being invalidated)
|
||||
// All non-noexcept functions can throw this
|
||||
struct InvalidatedException : public std::runtime_error {
|
||||
InvalidatedException() : std::runtime_error("Access to invalidated Results objects") {}
|
||||
struct InvalidatedException : public std::logic_error {
|
||||
InvalidatedException() : std::logic_error("Access to invalidated Results objects") {}
|
||||
};
|
||||
|
||||
// The input index parameter was out of bounds
|
||||
@ -153,20 +153,20 @@ public:
|
||||
};
|
||||
|
||||
// The input Row object is not attached
|
||||
struct DetatchedAccessorException : public std::runtime_error {
|
||||
DetatchedAccessorException() : std::runtime_error("Atempting to access an invalid object") {}
|
||||
struct DetatchedAccessorException : public std::logic_error {
|
||||
DetatchedAccessorException() : std::logic_error("Atempting to access an invalid object") {}
|
||||
};
|
||||
|
||||
// The input Row object belongs to a different table
|
||||
struct IncorrectTableException : public std::runtime_error {
|
||||
IncorrectTableException(StringData e, StringData a, const std::string &error)
|
||||
: std::runtime_error(error), expected(e), actual(a) {}
|
||||
struct IncorrectTableException : public std::logic_error {
|
||||
IncorrectTableException(StringData e, StringData a, const std::string &error) :
|
||||
std::logic_error(error), expected(e), actual(a) {}
|
||||
const StringData expected;
|
||||
const StringData actual;
|
||||
};
|
||||
|
||||
// The requested aggregate operation is not supported for the column type
|
||||
struct UnsupportedColumnTypeException : public std::runtime_error {
|
||||
struct UnsupportedColumnTypeException : public std::logic_error {
|
||||
size_t column_index;
|
||||
StringData column_name;
|
||||
DataType column_type;
|
||||
|
@ -511,4 +511,4 @@ util::Optional<int> Realm::file_format_upgraded_from_version() const
|
||||
}
|
||||
|
||||
MismatchedConfigException::MismatchedConfigException(StringData message, StringData path)
|
||||
: std::runtime_error(util::format(message.data(), path)) { }
|
||||
: std::logic_error(util::format(message.data(), path)) { }
|
||||
|
@ -228,19 +228,19 @@ namespace realm {
|
||||
std::string m_underlying;
|
||||
};
|
||||
|
||||
class MismatchedConfigException : public std::runtime_error {
|
||||
class MismatchedConfigException : public std::logic_error {
|
||||
public:
|
||||
MismatchedConfigException(StringData message, StringData path);
|
||||
};
|
||||
|
||||
class InvalidTransactionException : public std::runtime_error {
|
||||
class InvalidTransactionException : public std::logic_error {
|
||||
public:
|
||||
InvalidTransactionException(std::string message) : std::runtime_error(move(message)) {}
|
||||
InvalidTransactionException(std::string message) : std::logic_error(move(message)) {}
|
||||
};
|
||||
|
||||
class IncorrectThreadException : public std::runtime_error {
|
||||
class IncorrectThreadException : public std::logic_error {
|
||||
public:
|
||||
IncorrectThreadException() : std::runtime_error("Realm accessed from incorrect thread.") {}
|
||||
IncorrectThreadException() : std::logic_error("Realm accessed from incorrect thread.") {}
|
||||
};
|
||||
|
||||
class UninitializedRealmException : public std::runtime_error {
|
||||
@ -248,9 +248,9 @@ namespace realm {
|
||||
UninitializedRealmException(std::string message) : std::runtime_error(move(message)) {}
|
||||
};
|
||||
|
||||
class InvalidEncryptionKeyException : public std::runtime_error {
|
||||
class InvalidEncryptionKeyException : public std::logic_error {
|
||||
public:
|
||||
InvalidEncryptionKeyException() : std::runtime_error("Encryption key must be 64 bytes.") {}
|
||||
InvalidEncryptionKeyException() : std::logic_error("Encryption key must be 64 bytes.") {}
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user