From 34de8c4f268c1e657c780cfe13ace1e7feeacf53 Mon Sep 17 00:00:00 2001 From: dfahlander Date: Mon, 22 Jan 2024 10:57:34 +0100 Subject: [PATCH] Fail fast on Table.get(undefined) 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 https://github.com/dexie/Dexie.js/issues/1806#issuecomment-1884977367 --- src/classes/table/table.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/classes/table/table.ts b/src/classes/table/table.ts index 151389367..19e5cfedc 100644 --- a/src/classes/table/table.ts +++ b/src/classes/table/table.ts @@ -78,6 +78,7 @@ export class Table implements ITable { 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})