SQLite User Forum

TypeError: Cannot read properties of undefined (reading 'sqlite3_wasm_db_error')
Login

TypeError: Cannot read properties of undefined (reading 'sqlite3_wasm_db_error')

(1) By anonymous on 2023-09-29 03:46:51 [source]

Getting this when I use the WASM build from https://github.com/sqlite/sqlite-wasm - if I pass a bad argument to a function. I'd expect an error, but it looks like there's an error trying to even generate the error, so I can't see what the error message is.

Happens with a very basic setup:

import sqlite3InitModule from '@sqlite.org/sqlite-wasm';

const sqlite = await sqlite3InitModule() const sqliteDb = new sqlite.oo1.DB("file.sqlite", "ct") const x = sqlite.capi.sqlite3_prepare_v3("bad argument")

Looks like here's where it gets triggered:

const __dbArgcMismatch = (pDb, f, n) => { return sqlite3.util.sqlite3_wasm_db_error( pDb, capi.SQLITE_MISUSE, f + '() requires ' + n + ' argument' + (1 === n ? '' : 's') + '.', ); };

The next function calls "util.sqlite3_wasm_db_error" - is "sqlite3.util.sqlite3_wasm_db_error" just a typo?

(2) By Stephan Beal (stephan) on 2023-09-29 08:41:37 in reply to 1 [link] [source]

if I pass a bad argument to a function.

By and large, the API does not attempt to protect users from such misuse, relying instead on JS's own mechanisms for reporting it, as it's doing in your case.

(3) By anonymous on 2023-09-30 12:55:26 in reply to 2 [link] [source]

It's not doing that though, it's crashing when trying to report the error. There's a bug in the code that passes the error along.

I confirmed that "sqlite3.util.sqlite3_wasm_db_error" should be "util.sqlite3_wasm_db_error" - that fixes it and then I get the correct error message reported in JS.

(4.2) By Stephan Beal (stephan) on 2023-09-30 13:16:56 edited from 4.1 in reply to 3 [link] [source]

It's not doing that though, it's crashing when trying to report the error. There's a bug in the code that passes the error along.

It's attempting to report the error because you've passed in an invalid argument, so it's the bad argument which is causing the error-reporting error :).

This will be fixed but it won't show up in the npm project until the 3.44 release. (Edit: or the next 3.43.x release, if there is one.)

Edit: BTW...

The next function calls "util.sqlite3_wasm_db_error" - is "sqlite3.util.sqlite3_wasm_db_error" just a typo?

The "util" namespace is removed at the end of the setup process (it's strictly for internal use), so that part needs to remove the "sqlite3." prefix, as it's only valid during the initial library bootstrapping process.