mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-01 08:48:49 +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:
parent
108de5dea0
commit
001949d77a
Notes:
sideshowbarker
2024-07-17 23:11:33 +09:00
Author: https://github.com/JanDeVisser
Commit: 001949d77a
Pull-request: https://github.com/SerenityOS/serenity/pull/10911
Issue: https://github.com/SerenityOS/serenity/issues/10667
Issue: https://github.com/SerenityOS/serenity/issues/10730
Reviewed-by: https://github.com/Dexesttp
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/timschumi
Reviewed-by: https://github.com/trflynn89 ✅
15 changed files with 355 additions and 140 deletions
|
@ -12,10 +12,16 @@ namespace SQL::AST {
|
|||
RefPtr<SQLResult> CreateTable::execute(ExecutionContext& context) const
|
||||
{
|
||||
auto schema_name = (!m_schema_name.is_null() && !m_schema_name.is_empty()) ? m_schema_name : "default";
|
||||
auto schema_def = context.database->get_schema(schema_name);
|
||||
auto schema_def_or_error = context.database->get_schema(schema_name);
|
||||
if (schema_def_or_error.is_error())
|
||||
return SQLResult::construct(SQLCommand::Create, SQLErrorCode::InternalError, schema_def_or_error.error());
|
||||
auto schema_def = schema_def_or_error.release_value();
|
||||
if (!schema_def)
|
||||
return SQLResult::construct(SQLCommand::Create, SQLErrorCode::SchemaDoesNotExist, m_schema_name);
|
||||
auto table_def = context.database->get_table(schema_name, m_table_name);
|
||||
auto table_def_or_error = context.database->get_table(schema_name, m_table_name);
|
||||
if (table_def_or_error.is_error())
|
||||
return SQLResult::construct(SQLCommand::Create, SQLErrorCode::InternalError, table_def_or_error.error());
|
||||
auto table_def = table_def_or_error.release_value();
|
||||
if (table_def) {
|
||||
if (m_is_error_if_table_exists) {
|
||||
return SQLResult::construct(SQLCommand::Create, SQLErrorCode::TableExists, m_table_name);
|
||||
|
@ -37,7 +43,8 @@ RefPtr<SQLResult> CreateTable::execute(ExecutionContext& context) const
|
|||
}
|
||||
table_def->append_column(column.name(), type);
|
||||
}
|
||||
context.database->add_table(*table_def);
|
||||
if (auto maybe_error = context.database->add_table(*table_def); maybe_error.is_error())
|
||||
return SQLResult::construct(SQLCommand::Create, SQLErrorCode::InternalError, maybe_error.release_error());
|
||||
return SQLResult::construct(SQLCommand::Create, 0, 1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue