Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Hanaasagi opened this issue Oct 17, 2023 · 1 comment

Comments

@Hanaasagi
Copy link

Hanaasagi commented Oct 17, 2023

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.

@Prinzhorn
Copy link
Contributor

Prinzhorn commented Oct 18, 2023

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

unsigned char* data = sqlite3_serialize(db->db_handle, *attached_name, &length, 0);
if (!data && length) {
ThrowError("Out of memory");
return;
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants