From 1fe6060ff9da407fdae6fe4a28b97c380d609b03 Mon Sep 17 00:00:00 2001 From: stelar7 Date: Thu, 8 May 2025 09:48:06 +0200 Subject: [PATCH] LibWeb/IDB: Improve error messages slightly --- Libraries/LibWeb/IndexedDB/IDBCursor.cpp | 2 +- Libraries/LibWeb/IndexedDB/IDBDatabase.cpp | 13 ++++++++----- Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp | 4 ++-- Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp | 8 ++++---- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Libraries/LibWeb/IndexedDB/IDBCursor.cpp b/Libraries/LibWeb/IndexedDB/IDBCursor.cpp index 4128438ac9d..6d90608c32c 100644 --- a/Libraries/LibWeb/IndexedDB/IDBCursor.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBCursor.cpp @@ -98,7 +98,7 @@ WebIDL::ExceptionOr IDBCursor::continue_(JS::Value key) // 4. If this's got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an "InvalidStateError" DOMException. if (!m_got_value) - return WebIDL::InvalidStateError::create(realm, "Cursor is active or EOL"_string); + return WebIDL::InvalidStateError::create(realm, "Cursor is active or EOL while continuing"_string); // 5. If key is given, then: GC::Ptr key_value; diff --git a/Libraries/LibWeb/IndexedDB/IDBDatabase.cpp b/Libraries/LibWeb/IndexedDB/IDBDatabase.cpp index d793f80ef1c..4aff5790ba7 100644 --- a/Libraries/LibWeb/IndexedDB/IDBDatabase.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBDatabase.cpp @@ -189,16 +189,19 @@ WebIDL::ExceptionOr IDBDatabase::delete_object_store(String const& name) return {}; } +// https://w3c.github.io/IndexedDB/#dom-idbdatabase-transaction WebIDL::ExceptionOr> IDBDatabase::transaction(Variant> store_names, Bindings::IDBTransactionMode mode, IDBTransactionOptions options) { + auto& realm = this->realm(); + // 1. If a live upgrade transaction is associated with the connection, throw an "InvalidStateError" DOMException. auto database = associated_database(); if (database->upgrade_transaction()) - return WebIDL::InvalidStateError::create(realm(), "Upgrade transaction is live"_string); + return WebIDL::InvalidStateError::create(realm, "Upgrade transaction is live"_string); // 2. If this's close pending flag is true, then throw an "InvalidStateError" DOMException. if (close_pending()) - return WebIDL::InvalidStateError::create(realm(), "Close pending"_string); + return WebIDL::InvalidStateError::create(realm, "Close pending"_string); // 3. Let scope be the set of unique strings in storeNames if it is a sequence, or a set containing one string equal to storeNames otherwise. Vector scope; @@ -211,12 +214,12 @@ WebIDL::ExceptionOr> IDBDatabase::transaction(Variantobject_store_with_name(store_name)) - return WebIDL::NotFoundError::create(realm(), "Object store not found"_string); + return WebIDL::NotFoundError::create(realm, "Provided object store names does not exist in database"_string); } // 5. If scope is empty, throw an "InvalidAccessError" DOMException. if (scope.is_empty()) - return WebIDL::InvalidAccessError::create(realm(), "Scope is empty"_string); + return WebIDL::InvalidAccessError::create(realm, "Scope is empty"_string); // 6. If mode is not "readonly" or "readwrite", throw a TypeError. if (mode != Bindings::IDBTransactionMode::Readonly && mode != Bindings::IDBTransactionMode::Readwrite) @@ -229,7 +232,7 @@ WebIDL::ExceptionOr> IDBDatabase::transaction(Variantset_cleanup_event_loop(HTML::main_thread_event_loop()); diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp index 5641bfb8edc..c582dba9abd 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp @@ -188,7 +188,7 @@ WebIDL::ExceptionOr> IDBObjectStore::index(String const& name) // 5. Let index be the index named name in this’s index set if one exists, or throw a "NotFoundError" DOMException otherwise. auto index = m_indexes.get(name); if (!index.has_value()) - return WebIDL::NotFoundError::create(realm(), "Index not found"_string); + return WebIDL::NotFoundError::create(realm(), "Index not found in object store"_string); // 6. Return an index handle associated with index and this. return IDBIndex::create(realm(), *index, *this); @@ -218,7 +218,7 @@ WebIDL::ExceptionOr IDBObjectStore::delete_index(String const& name) // 6. Let index be the index named name in store if one exists, or throw a "NotFoundError" DOMException otherwise. auto index = m_indexes.get(name); if (!index.has_value()) - return WebIDL::NotFoundError::create(realm, "Index not found"_string); + return WebIDL::NotFoundError::create(realm, "Index not found while trying to delete it"_string); // 7. Remove index from this’s index set. m_indexes.remove(name); diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp index c094b0815aa..568b8fd2583 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp @@ -960,7 +960,7 @@ WebIDL::ExceptionOr> evaluate_key_path_on_a_value(JS::Realm& else { // 1. If Type(value) is not Object, return failure. if (!value.is_object()) - return Error::from_string_literal("Value is not an object"); + return Error::from_string_literal("Value is not an object during key path evaluation"); auto identifier_property = String::from_utf8_without_validation(identifier.bytes()); @@ -969,14 +969,14 @@ WebIDL::ExceptionOr> evaluate_key_path_on_a_value(JS::Realm& // 3. If hop is false, return failure. if (!hop) - return Error::from_string_literal("Property does not exist"); + return Error::from_string_literal("Failed to find property on object during key path evaluation"); // 4. Let value be ! Get(value, identifier). value = MUST(value.as_object().get(identifier_property)); // 5. If value is undefined, return failure. if (value.is_undefined()) - return Error::from_string_literal("Value is undefined"); + return Error::from_string_literal("undefined value on object during key path evaluation"); } return {}; @@ -1229,7 +1229,7 @@ ErrorOr generate_a_key(GC::Ref store) // 3. If key is greater than 2^53 (9007199254740992), then return failure. if (key > static_cast(MAX_KEY_GENERATOR_VALUE)) - return Error::from_string_literal("Key is greater than 2^53"); + return Error::from_string_literal("Key is greater than 2^53 while trying to generate a key"); // 4. Increase generator’s current number by 1. generator.increment(1);