From 8c6c24192cc6ef7e2199daa1ddb2853277ccc8cb Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sat, 12 Mar 2022 23:46:03 +0100 Subject: [PATCH] Document error codes of `classic-level` and `many-level` Ref https://github.com/Level/classic-level/pull/8 --- README.md | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index df77e2d..93f29d6 100644 --- a/README.md +++ b/README.md @@ -78,9 +78,15 @@ - [`LEVEL_INVALID_KEY`](#level_invalid_key) - [`LEVEL_INVALID_VALUE`](#level_invalid_value) - [`LEVEL_CORRUPTION`](#level_corruption) + - [`LEVEL_IO_ERROR`](#level_io_error) - [`LEVEL_INVALID_PREFIX`](#level_invalid_prefix) - [`LEVEL_NOT_SUPPORTED`](#level_not_supported) - [`LEVEL_LEGACY`](#level_legacy) + - [`LEVEL_LOCKED`](#level_locked) + - [`LEVEL_READONLY`](#level_readonly) + - [`LEVEL_ASSERT`](#level_assert) + - [`LEVEL_CONNECTION_LOST`](#level_connection_lost) + - [`LEVEL_REMOTE_ERROR`](#level_remote_error) - [Shared Access](#shared-access) - [Private API For Implementors](#private-api-for-implementors) - [Example](#example) @@ -809,7 +815,10 @@ try { await db.open() } catch (err) { console.error(err.code) // 'LEVEL_DATABASE_NOT_OPEN' - console.error(err.cause) // 'Error: Failed to acquire lock' + + if (err.cause && err.cause.code === 'LEVEL_LOCKED') { + // Another process or instance has opened the database + } } ``` @@ -864,6 +873,10 @@ When a value is `null`, `undefined` or (if an implementation deems it so) otherw Data could not be read (from an underlying store) due to a corruption. +#### `LEVEL_IO_ERROR` + +Data could not be read (from an underlying store) due to an input/output error, for example from the filesystem. + #### `LEVEL_INVALID_PREFIX` When a sublevel prefix contains characters outside of the supported byte range. @@ -890,6 +903,26 @@ module.exports = function plugin (db) { When a method, option or other property was used that has been removed from the API. +#### `LEVEL_LOCKED` + +When an attempt was made to open a database that is already open in another process or instance. Used by `classic-level` and other implementations of `abstract-level` that use exclusive locks. + +#### `LEVEL_READONLY` + +When an attempt was made to write data to a read-only database. Used by `many-level`. + +#### `LEVEL_ASSERT` + +When an internal assertion failed. This could indicate a bug. If so, please open a detailed issue in the relevant repository or [`Level/community`](https://github.com/Level/community) when in doubt. Be sure to include steps to reproduce. + +#### `LEVEL_CONNECTION_LOST` + +When a database relies on a connection to a remote party and that connection has been lost. Used by `many-level`. + +#### `LEVEL_REMOTE_ERROR` + +When a remote party encountered an unexpected condition that it can't reflect with a more specific code. Used by `many-level`. + ### Shared Access Unless documented otherwise, implementations of `abstract-level` do _not_ support accessing a database from multiple processes running in parallel. That includes Node.js clusters and Electron renderer processes.