Skip to content

Commit

Permalink
trie: simplify get method logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau committed Aug 30, 2022
1 parent d78f903 commit 089295e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
9 changes: 5 additions & 4 deletions packages/trie/benchmarks/engines/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ export class LevelDB implements DB {
try {
value = await this._leveldb.get(key, ENCODING_OPTS)
} catch (error: any) {
if (error.notFound !== undefined) {
// not found, returning null
} else {
// https://github.com/Level/abstract-level/blob/915ad1317694d0ce8c580b5ab85d81e1e78a3137/abstract-level.js#L309
// This should be `true` if the error came from LevelDB
// so we can check for `NOT true` to identify any non-404 errors
if (error.notFound !== true) {
throw error
}
}
return value as Buffer
return value
}

/**
Expand Down
9 changes: 5 additions & 4 deletions packages/trie/recipes/level-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ export class LevelDB implements DB {
try {
value = await this._leveldb.get(key, ENCODING_OPTS)
} catch (error: any) {
if (error.notFound !== undefined) {
// not found, returning null
} else {
// https://github.com/Level/abstract-level/blob/915ad1317694d0ce8c580b5ab85d81e1e78a3137/abstract-level.js#L309
// This should be `true` if the error came from LevelDB
// so we can check for `NOT true` to identify any non-404 errors
if (error.notFound !== true) {
throw error
}
}
return value as Buffer
return value
}

async put(key: Buffer, val: Buffer): Promise<void> {
Expand Down
9 changes: 5 additions & 4 deletions packages/trie/recipes/level.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ export class LevelDB implements DB {
try {
value = await this._leveldb.get(key, ENCODING_OPTS)
} catch (error: any) {
if (error.notFound !== undefined) {
// not found, returning null
} else {
// https://github.com/Level/abstract-level/blob/915ad1317694d0ce8c580b5ab85d81e1e78a3137/abstract-level.js#L309
// This should be `true` if the error came from LevelDB
// so we can check for `NOT true` to identify any non-404 errors
if (error.notFound !== true) {
throw error
}
}
return value as Buffer
return value
}

async put(key: Buffer, val: Buffer): Promise<void> {
Expand Down

0 comments on commit 089295e

Please sign in to comment.