Skip to content

Commit 4b3464c

Browse files
authored
Document error codes of classic-level and many-level (#20)
Ref Level/classic-level#8
1 parent 2935180 commit 4b3464c

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@
7878
- [`LEVEL_INVALID_KEY`](#level_invalid_key)
7979
- [`LEVEL_INVALID_VALUE`](#level_invalid_value)
8080
- [`LEVEL_CORRUPTION`](#level_corruption)
81+
- [`LEVEL_IO_ERROR`](#level_io_error)
8182
- [`LEVEL_INVALID_PREFIX`](#level_invalid_prefix)
8283
- [`LEVEL_NOT_SUPPORTED`](#level_not_supported)
8384
- [`LEVEL_LEGACY`](#level_legacy)
85+
- [`LEVEL_LOCKED`](#level_locked)
86+
- [`LEVEL_READONLY`](#level_readonly)
87+
- [`LEVEL_CONNECTION_LOST`](#level_connection_lost)
88+
- [`LEVEL_REMOTE_ERROR`](#level_remote_error)
8489
- [Shared Access](#shared-access)
8590
- [Private API For Implementors](#private-api-for-implementors)
8691
- [Example](#example)
@@ -805,7 +810,10 @@ try {
805810
await db.open()
806811
} catch (err) {
807812
console.error(err.code) // 'LEVEL_DATABASE_NOT_OPEN'
808-
console.error(err.cause) // 'Error: Failed to acquire lock'
813+
814+
if (err.cause && err.cause.code === 'LEVEL_LOCKED') {
815+
// Another process or instance has opened the database
816+
}
809817
}
810818
```
811819

@@ -860,6 +868,10 @@ When a value is `null`, `undefined` or (if an implementation deems it so) otherw
860868

861869
Data could not be read (from an underlying store) due to a corruption.
862870

871+
#### `LEVEL_IO_ERROR`
872+
873+
Data could not be read (from an underlying store) due to an input/output error, for example from the filesystem.
874+
863875
#### `LEVEL_INVALID_PREFIX`
864876

865877
When a sublevel prefix contains characters outside of the supported byte range.
@@ -886,6 +898,22 @@ module.exports = function plugin (db) {
886898

887899
When a method, option or other property was used that has been removed from the API.
888900

901+
#### `LEVEL_LOCKED`
902+
903+
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.
904+
905+
#### `LEVEL_READONLY`
906+
907+
When an attempt was made to write data to a read-only database. Used by `many-level`.
908+
909+
#### `LEVEL_CONNECTION_LOST`
910+
911+
When a database relies on a connection to a remote party and that connection has been lost. Used by `many-level`.
912+
913+
#### `LEVEL_REMOTE_ERROR`
914+
915+
When a remote party encountered an unexpected condition that it can't reflect with a more specific code. Used by `many-level`.
916+
889917
### Shared Access
890918

891919
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.

0 commit comments

Comments
 (0)