mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 03:09:08 +00:00
LibSQL: Improve error handling
The handling of filesystem level errors was basically non-existing or consisting of `VERIFY_NOT_REACHED` assertions. Addressed this by * Adding `open` methods to `Heap` and `Database` which return errors. * Changing the interface of methods of these classes and clients downstream to propagate these errors. The constructors of `Heap` and `Database` don't open the underlying filesystem file anymore. The SQL statement handlers return an `SQLErrorCode::InternalError` error code if an error comes back from the lower levels. Note that some of these errors are things like duplicate index entry errors that should be caught before the SQL layer attempts to actually update the database. Added tests to catch attempts to open weird or non-existent files as databases. Finally, in between me writing this patch and submitting the PR the AK::Result<Foo, Bar> template got deprecated in favour of ErrorOr<Foo>. This resulted in more busywork.
This commit is contained in:
committed by
Ali Mohammad Pur
parent
108de5dea0
commit
001949d77a
@@ -66,7 +66,8 @@ Value BinaryOperatorExpression::evaluate(ExecutionContext& context) const
|
||||
switch (type()) {
|
||||
case BinaryOperator::Concatenate: {
|
||||
if (lhs_value.type() != SQLType::Text) {
|
||||
VERIFY_NOT_REACHED();
|
||||
context.result->set_error(SQLErrorCode::BooleanOperatorTypeMismatch, BinaryOperator_name(type()));
|
||||
return Value::null();
|
||||
}
|
||||
AK::StringBuilder builder;
|
||||
builder.append(lhs_value.to_string());
|
||||
@@ -110,7 +111,7 @@ Value BinaryOperatorExpression::evaluate(ExecutionContext& context) const
|
||||
context.result->set_error(SQLErrorCode::BooleanOperatorTypeMismatch, BinaryOperator_name(type()));
|
||||
return Value::null();
|
||||
}
|
||||
return Value(lhs_bool_maybe.value() && rhs_bool_maybe.value());
|
||||
return Value(lhs_bool_maybe.release_value() && rhs_bool_maybe.release_value());
|
||||
}
|
||||
case BinaryOperator::Or: {
|
||||
auto lhs_bool_maybe = lhs_value.to_bool();
|
||||
@@ -119,7 +120,7 @@ Value BinaryOperatorExpression::evaluate(ExecutionContext& context) const
|
||||
context.result->set_error(SQLErrorCode::BooleanOperatorTypeMismatch, BinaryOperator_name(type()));
|
||||
return Value::null();
|
||||
}
|
||||
return Value(lhs_bool_maybe.value() || rhs_bool_maybe.value());
|
||||
return Value(lhs_bool_maybe.release_value() || rhs_bool_maybe.release_value());
|
||||
}
|
||||
default:
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
Reference in New Issue
Block a user