better-sqlite3 icon indicating copy to clipboard operation
better-sqlite3 copied to clipboard

Misleading error messages when passing an incorrect schema in `serialize()`.

Open Hanaasagi opened this issue 2 years ago • 1 comments

My Env

  • better-sqlite3: 9.0.0
  • Linux 6.5.7-arch1-1 x86_64 unknown
  • sqlite3: 3.43.2 2023-10-10 12:14:04 4310099cce5a487035fa535dd3002c59ac7f1d1bec68d7cf317fd3e76948alt1 (64-bit)

Repro

import Database from "better-sqlite3";

const db = new Database(":memory:");
// Out of memory
db.serialize({ attached: "foobar" });
// work as expected
// db.serialize({ attached: "main" });

What I see

/home/********/node_modules/better-sqlite3/lib/methods/serialize.js:15
        return this[cppdb].serialize(attachedName);
                           ^

Error: Out of memory

Expected behavior

some error like schema not found.

Hanaasagi avatar Oct 17 '23 12:10 Hanaasagi

Yep, seems like this does not account for this case:

https://github.com/WiseLibs/better-sqlite3/blob/007d43e229190618884a9f976909c0b14a17d82c/src/objects/database.lzz#L285-L290

So maybe the error message could be updated to be more generic.

some error like schema not found.

sqlite3_serialize does not provide this information and it does not seem to be trivial to get it (ChatGTP suggests parsing the result of PRAGMA database_list;)

Prinzhorn avatar Oct 18 '23 06:10 Prinzhorn