Skip to content

Commit

Permalink
Fail fast on Table.get(undefined)
Browse files Browse the repository at this point in the history
It's a common pitfall to do db.someTable.get(someVariable) without checking that someVariable isn't null.

This is a common pitfall and in the case the call to Table.get() is the initial db call that the application makes, the call stack will be totally unreadable because:

1. Table.get() will first asynchronically auto-open the database.
2. Whe DB is finally opened it will fail deep inside DBCore leaving the user with an unreadable call stack.

See #1806 (comment)
  • Loading branch information
dfahlander committed Jan 22, 2024
1 parent 5c93379 commit 34de8c4
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/classes/table/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class Table implements ITable<any, IndexableType> {
get(keyOrCrit, cb?) {
if (keyOrCrit && keyOrCrit.constructor === Object)
return this.where(keyOrCrit as { [key: string]: IndexableType }).first(cb);
if (keyOrCrit == null) return rejection(new exceptions.Type(`Invalid argument to Table.get()`));

return this._trans('readonly', (trans) => {
return this.core.get({trans, key: keyOrCrit})
Expand Down

0 comments on commit 34de8c4

Please sign in to comment.