Skip to content

Commit 84650c5

Browse files
os-zhuangclaude
andauthored
fix(driver-sql): don't dump a scary ERR_DLOPEN stack for the native→wasm probe (#2892)
* fix(driver-sql): don't dump a scary ERR_DLOPEN stack for the native→wasm probe 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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UUWGgTT5s7XgBb2eLtzhfU * chore(changeset): patch @objectstack/driver-sql for the ERR_DLOPEN log-noise fix Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UUWGgTT5s7XgBb2eLtzhfU --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent a09aa95 commit 84650c5

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@objectstack/driver-sql": patch
3+
---
4+
5+
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.

packages/plugins/driver-sql/src/sql-driver.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,33 @@ export class SqlDriver implements IDataDriver {
580580
try {
581581
await this.knex.raw('PRAGMA auto_vacuum = INCREMENTAL');
582582
} catch (e) {
583-
this.logger.warn('Failed to set PRAGMA auto_vacuum=INCREMENTAL', e);
583+
// A native better-sqlite3 load failure surfaces HERE first — this PRAGMA
584+
// is the first query that forces the lazy `.node` addon to load. Two
585+
// real-world variants, both handled by `resolveSqliteDriver`'s probe,
586+
// which catches the failure and steps down to wasm SQLite with a clean
587+
// one-line notice (#2229):
588+
// • ABI mismatch — `ERR_DLOPEN_FAILED` / "…NODE_MODULE_VERSION 127…"
589+
// (a stale prebuilt binary after a Node upgrade)
590+
// • not built — "Could not locate the bindings file" (native addon
591+
// never compiled, e.g. a fresh clone / blocked build)
592+
// Dumping the full multi-line stack for either looks like a fatal crash
593+
// to the reader (it isn't), so log a concise, actionable one-liner and
594+
// let the step-down message that follows explain the outcome. Any OTHER
595+
// PRAGMA failure keeps the full warning (with stack) as before.
596+
const code = (e as { code?: string } | null | undefined)?.code;
597+
const msg = e instanceof Error ? e.message : String(e);
598+
const isNativeLoadFailure =
599+
code === 'ERR_DLOPEN_FAILED' ||
600+
code === 'MODULE_NOT_FOUND' ||
601+
code === 'ERR_MODULE_NOT_FOUND' ||
602+
/NODE_MODULE_VERSION|could not locate the bindings|was compiled against a different/i.test(msg);
603+
if (isNativeLoadFailure) {
604+
this.logger.warn(
605+
'native better-sqlite3 unavailable (ABI mismatch or not built) — will step down to wasm SQLite; run `pnpm rebuild better-sqlite3` for native speed',
606+
);
607+
} else {
608+
this.logger.warn('Failed to set PRAGMA auto_vacuum=INCREMENTAL', e);
609+
}
584610
}
585611
}
586612
}

0 commit comments

Comments
 (0)