From 121113ef22a22781e01d65e1496d428ef52480b5 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 14 Jul 2026 03:40:40 +0000 Subject: [PATCH 1/2] =?UTF-8?q?fix(driver-sql):=20don't=20dump=20a=20scary?= =?UTF-8?q?=20ERR=5FDLOPEN=20stack=20for=20the=20native=E2=86=92wasm=20pro?= =?UTF-8?q?be?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When native better-sqlite3 has an ABI mismatch (`NODE_MODULE_VERSION` after a Node upgrade), `resolveSqliteDriver`'s probe deliberately triggers the lazy `.node` load to detect it and steps down to wasm SQLite with a clean one-line notice (#2229). But `SqlDriver.connect()`'s best-effort `PRAGMA auto_vacuum` is the first query to force that load, so the failure surfaced there first and was logged with the full multi-line `ERR_DLOPEN_FAILED` stack — twice — making a handled, non-fatal step-down look like a fatal crash to anyone reading the dev console. Detect the native-addon load failure (`code === 'ERR_DLOPEN_FAILED'` or a `NODE_MODULE_VERSION` message) in that catch and log a concise, actionable one-liner instead of the stack, pointing at `pnpm rebuild better-sqlite3`. The following step-down notice still explains the outcome. Any OTHER PRAGMA failure keeps the full warning (with stack) unchanged. Purely a log-noise fix — control flow and the fallback behavior are untouched. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01UUWGgTT5s7XgBb2eLtzhfU --- packages/plugins/driver-sql/src/sql-driver.ts | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/plugins/driver-sql/src/sql-driver.ts b/packages/plugins/driver-sql/src/sql-driver.ts index c44d23218b..dffa932d78 100644 --- a/packages/plugins/driver-sql/src/sql-driver.ts +++ b/packages/plugins/driver-sql/src/sql-driver.ts @@ -580,7 +580,33 @@ export class SqlDriver implements IDataDriver { try { await this.knex.raw('PRAGMA auto_vacuum = INCREMENTAL'); } catch (e) { - this.logger.warn('Failed to set PRAGMA auto_vacuum=INCREMENTAL', e); + // A native better-sqlite3 load failure surfaces HERE first — this PRAGMA + // is the first query that forces the lazy `.node` addon to load. Two + // real-world variants, both handled by `resolveSqliteDriver`'s probe, + // which catches the failure and steps down to wasm SQLite with a clean + // one-line notice (#2229): + // • ABI mismatch — `ERR_DLOPEN_FAILED` / "…NODE_MODULE_VERSION 127…" + // (a stale prebuilt binary after a Node upgrade) + // • not built — "Could not locate the bindings file" (native addon + // never compiled, e.g. a fresh clone / blocked build) + // Dumping the full multi-line stack for either looks like a fatal crash + // to the reader (it isn't), so log a concise, actionable one-liner and + // let the step-down message that follows explain the outcome. Any OTHER + // PRAGMA failure keeps the full warning (with stack) as before. + const code = (e as { code?: string } | null | undefined)?.code; + const msg = e instanceof Error ? e.message : String(e); + const isNativeLoadFailure = + code === 'ERR_DLOPEN_FAILED' || + code === 'MODULE_NOT_FOUND' || + code === 'ERR_MODULE_NOT_FOUND' || + /NODE_MODULE_VERSION|could not locate the bindings|was compiled against a different/i.test(msg); + if (isNativeLoadFailure) { + this.logger.warn( + 'native better-sqlite3 unavailable (ABI mismatch or not built) — will step down to wasm SQLite; run `pnpm rebuild better-sqlite3` for native speed', + ); + } else { + this.logger.warn('Failed to set PRAGMA auto_vacuum=INCREMENTAL', e); + } } } } From d0667fd61232e718d804484f192aceea523f3414 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 14 Jul 2026 03:54:48 +0000 Subject: [PATCH 2/2] chore(changeset): patch @objectstack/driver-sql for the ERR_DLOPEN log-noise fix Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01UUWGgTT5s7XgBb2eLtzhfU --- .changeset/driver-sql-quiet-dlopen-probe.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/driver-sql-quiet-dlopen-probe.md diff --git a/.changeset/driver-sql-quiet-dlopen-probe.md b/.changeset/driver-sql-quiet-dlopen-probe.md new file mode 100644 index 0000000000..cb9915144a --- /dev/null +++ b/.changeset/driver-sql-quiet-dlopen-probe.md @@ -0,0 +1,5 @@ +--- +"@objectstack/driver-sql": patch +--- + +Log a concise one-liner instead of the full `ERR_DLOPEN_FAILED` stack trace when native `better-sqlite3` cannot load (an ABI / `NODE_MODULE_VERSION` mismatch after a Node upgrade, or the native addon was never built). The native → wasm SQLite step-down is unchanged — this only stops a handled, non-fatal fallback from reading like a fatal crash in the dev console, and points at `pnpm rebuild better-sqlite3` for native speed. Any other `PRAGMA` failure keeps its full warning.