mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 06:18:59 +00:00
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.
32 lines
1.1 KiB
C++
32 lines
1.1 KiB
C++
/*
|
|
* Copyright (c) 2021, Jan de Visser <jan@de-visser.net>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibSQL/AST/AST.h>
|
|
#include <LibSQL/Database.h>
|
|
#include <LibSQL/Meta.h>
|
|
|
|
namespace SQL::AST {
|
|
|
|
RefPtr<SQLResult> CreateSchema::execute(ExecutionContext& context) const
|
|
{
|
|
auto schema_def_or_error = context.database->get_schema(m_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) {
|
|
if (m_is_error_if_schema_exists) {
|
|
return SQLResult::construct(SQLCommand::Create, SQLErrorCode::SchemaExists, m_schema_name);
|
|
}
|
|
return SQLResult::construct(SQLCommand::Create);
|
|
}
|
|
|
|
schema_def = SchemaDef::construct(m_schema_name);
|
|
if (auto maybe_error = context.database->add_schema(*schema_def); maybe_error.is_error())
|
|
return SQLResult::construct(SQLCommand::Create, SQLErrorCode::InternalError, maybe_error.error());
|
|
return SQLResult::construct(SQLCommand::Create, 0, 1);
|
|
}
|
|
|
|
}
|