diff --git a/files/en-us/web/api/idbcursor/key/index.md b/files/en-us/web/api/idbcursor/key/index.md index 65d3c5d898c9980..947256dabeee47a 100644 --- a/files/en-us/web/api/idbcursor/key/index.md +++ b/files/en-us/web/api/idbcursor/key/index.md @@ -17,6 +17,11 @@ key can be any data type. A value of any type. +### Exceptions + +- `InvalidStateError` {{domxref("DOMException")}} + - : Thrown if the cursor is advancing or has finished. + ## Examples In this simple fragment we create a transaction, retrieve an object store, then use a diff --git a/files/en-us/web/api/idbcursor/primarykey/index.md b/files/en-us/web/api/idbcursor/primarykey/index.md index 6d44c3b82c876e9..5fa13ceaf39bc48 100644 --- a/files/en-us/web/api/idbcursor/primarykey/index.md +++ b/files/en-us/web/api/idbcursor/primarykey/index.md @@ -17,6 +17,11 @@ undefined. The cursor's primary key can be any data type. A value of any data type. +### Exceptions + +- `InvalidStateError` {{domxref("DOMException")}} + - : Thrown if the cursor is advancing or has finished. + ## Examples In this simple fragment we create a transaction, retrieve an object store, then use a diff --git a/files/en-us/web/api/idbcursor/request/index.md b/files/en-us/web/api/idbcursor/request/index.md index 9527caeec4a36b8..7a42cdce60f1bfd 100644 --- a/files/en-us/web/api/idbcursor/request/index.md +++ b/files/en-us/web/api/idbcursor/request/index.md @@ -14,6 +14,11 @@ The **`request`** read-only property of the {{domxref("IDBCursor")}} interface r An {{domxref("IDBRequest")}} object instance. +### Exceptions + +- `InvalidStateError` {{domxref("DOMException")}} + - : Thrown if the cursor is already advancing. + ## Examples When you open a cursor, the `request` property is then available on that cursor object, to tell you what request object the cursor originated from. For example: diff --git a/files/en-us/web/api/idbdatabase/createobjectstore/index.md b/files/en-us/web/api/idbdatabase/createobjectstore/index.md index d2205109fee13db..2ad15379f933880 100644 --- a/files/en-us/web/api/idbdatabase/createobjectstore/index.md +++ b/files/en-us/web/api/idbdatabase/createobjectstore/index.md @@ -54,20 +54,22 @@ A new {{domxref("IDBObjectStore")}}. This method may raise a {{domxref("DOMException")}} with a `name` of one of the following types: +- `ConstraintError` {{domxref("DOMException")}} + - : Thrown if an object store with the given name (based on a case-sensitive comparison) + already exists in the connected database. +- `InvalidAccessError` {{domxref("DOMException")}} + - : Thrown if `autoIncrement` is set to true and `keyPath` is + either an empty string or an array containing an empty string. - `InvalidStateError` {{domxref("DOMException")}} - : Thrown if the method was not called from a `versionchange` transaction callback. +- `SyntaxError` + - : Thrown if the `keyPath` option contains an invalid key path. - `TransactionInactiveError` {{domxref("DOMException")}} - : Thrown if a request is made on a source database that does not exist (for example, when the database has been deleted or removed). In Firefox previous to version 41, an `InvalidStateError` was raised in this case as well, which was misleading; this has now been fixed (see [Firefox bug 1176165](https://bugzil.la/1176165)). -- `ConstraintError` {{domxref("DOMException")}} - - : Thrown if an object store with the given name (based on a case-sensitive comparison) - already exists in the connected database. -- `InvalidAccessError` {{domxref("DOMException")}} - - : Thrown if `autoIncrement` is set to true and `keyPath` is - either an empty string or an array containing an empty string. ## Examples diff --git a/files/en-us/web/api/idbobjectstore/clear/index.md b/files/en-us/web/api/idbobjectstore/clear/index.md index 4ba1dc7c6366722..47a62ee95dde6b9 100644 --- a/files/en-us/web/api/idbobjectstore/clear/index.md +++ b/files/en-us/web/api/idbobjectstore/clear/index.md @@ -36,6 +36,8 @@ If the operation is successful, the value of the request's {{domxref("IDBRequest ### Exceptions +- `InvalidStateError` {{domxref("DOMException")}} + - : Thrown if the object store has been deleted. - `ReadOnlyError` {{domxref("DOMException")}} - : Thrown if the transaction associated with this operation is in read-only [mode](/en-US/docs/Web/API/IDBTransaction/mode). - `TransactionInactiveError` {{domxref("DOMException")}} diff --git a/files/en-us/web/api/idbrequest/error/index.md b/files/en-us/web/api/idbrequest/error/index.md index 8c4c657ba154f68..c85de2a0eb23b23 100644 --- a/files/en-us/web/api/idbrequest/error/index.md +++ b/files/en-us/web/api/idbrequest/error/index.md @@ -10,62 +10,38 @@ browser-compat: api.IDBRequest.error The **`error`** read-only property of the {{domxref("IDBRequest")}} interface returns the error in the event of an unsuccessful -request. +request. If the request is not completed, the error is not available and an `InvalidStateError` exception is +thrown. ## Value -A {{domxref("DOMException")}} or `null` if there is no error. The following error names can be returned -in the exception object, depending on what caused the error. +A {{domxref("DOMException")}} or `null` if there is no error. The exception object will have one of the following names, depending on what caused the error. -### Transaction errors +These errors are asynchronous, meaning that they can't be handled via [`try...catch`](/en-US/docs/Web/JavaScript/Reference/Statements/try...catch). However, if an `IDBRequest` has an {{domxref("IDBRequest.error", "error")}} event handler assigned, you can still inspect such errors by querying the request's `error` property via the event object, for example [`event.target.error.name`](/en-US/docs/Web/API/DOMException/name) or [`event.target.error.message`](/en-US/docs/Web/API/DOMException/message). - `AbortError` - - : Thrown if you abort the transaction, then all requests still in progress receive this error. -- `ReadOnlyError` - - : Thrown if the mutating operation was attempted in a read-only transaction. -- `SyntaxError` - - : Thrown in the `keyPath` argument contains an invalid key path. -- `TransactionInactiveError` - - : Thrown if a request was placed against a transaction which is currently not active, or which is finished. - -### Data integrity errors - + - : If you abort the transaction, then all requests still in progress receive this error. - `ConstraintError` - - : Thrown if you insert data that doesn't conform to a constraint when creating stores and indexes. + - : Received if you insert data that doesn't conform to a constraint when creating stores and indexes. For example, you will get this error if you try to add a new key that already exists in the record. -- `DataError` - - : Thrown if data provided to an operation does not meet requirements. -- `DataCloneError` - - : Thrown if the data being stored could not be cloned by the internal structured cloning algorithm. -- `InvalidAccessError` - - : Thrown if an invalid operation was performed on an object. -- `InvalidStateError` - - : Thrown if an operation was called on an object on which it is not allowed or at a time when it is not allowed, or if a request is made on a source object that has been deleted or removed. For example, if a result is accessed before the corresponding request is completed. +- `DataError` or `UnknownError` + - : Received for transient read failure errors, including general disk IO errors. See "Large value read failure errors" below for more details. +- `NotFoundError` or `NotReadableError` + - : Received for unrecoverable read failure errors. See "Large value read failure errors" below for more details. - `QuotaExceededError` - - : Thrown if you run out of disk quota and the user declined to grant the application more space. + - : Received if the application runs out of disk quota. In some cases, browsers prompt the user for more space, and the error is received if they decline the request. In other cases, the browser uses heuristics to determine whether more space can be assigned. - `VersionError` - - : Thrown if you try to open a database with a version lower than the one it already has. + - : If you try to open a database with a version lower than the one it already has, this error is received. ### Large value read failure errors -Large IndexedDB values are not stored directly in the underlying database; instead, they are stored as separate files that are accessed via a reference stored in the database. This category of errors can occur due to transient causes such as low memory and unrecoverable causes such as source blob files being deleted. Separate blob files containing IndexedDB data can end up being deleted because they show up as opaque files to users when they are using disk space recovery programs. +Large value read failure errors occur when an IndexedDB stores large blob values (for example, audio files for an offline podcast app), and then subsequently fails to read those values. This category of errors can occur due to transient causes such as low memory and unrecoverable causes such as source blob files being deleted. -Possible corrective actions for such unrecoverable cases might include notifying the user, deleting the entry from the DB, then attempting to re-fetch the data from the server. - -Errors in this caregory are as follows. More recent browser versions have changed the error types thrown and improved the error messages to help developers distinguish between transient and unrecoverable cases. - -- `NotFoundError` or `NotReadableError` - - : Thrown for unrecoverable errors. -- `DataError` or `UnknownError` - - : Thrown for transient errors, including general disk IO errors. +Different IndexedDB implementations store large values in different ways. For example, in Chrome, large IndexedDB values are not stored directly in the underlying database; instead, they are stored as separate files that are accessed via a reference stored in the database. It has been observed that these separate files can end up being deleted because they show up as opaque files to users when they are using disk space recovery programs. -### Related errors +Possible corrective actions for such cases might include notifying the user, deleting the entry from the database, then attempting to re-fetch the data from the server. -In addition to the error codes sent to the {{ domxref("IDBRequest") }} object, -asynchronous operations can also raise exceptions. The list describes problems that -could occur when the request is being executed, but you might also encounter other -problems when the request is being made. For example, if the result is accessed -while the request is not completed, the `InvalidStateError` exception is thrown. +More recent browser versions have changed the error types and improved the error messages to help developers distinguish between transient and unrecoverable cases. ## Examples @@ -108,7 +84,8 @@ objectStoreTitleRequest.onsuccess = () => { objectStoreTitleRequest.onerror = () => { // If an error occurs with the request, log what it is console.log( - `There has been an error with retrieving your data: ${objectStoreTitleRequest.error}`, + `There has been an error with retrieving your data: + ${objectStoreTitleRequest.error.name}: ${objectStoreTitleRequest.error.message}`, ); }; ```