WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.26k stars 391 forks source link

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

Open Hanaasagi opened 9 months ago

Hanaasagi commented 9 months ago

My Env

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.

Prinzhorn commented 9 months ago

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;)