Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix(db): detect missing better-sqlite3 native binding from bun/skipped postinstall (#2358)
diegosouzapw4b2e9b780ab6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 488149befb..c78c9d2f41 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -139,6 +139,8 @@- **build(deps):** production group bumps — 4 updates. ([#2398](https://github.com/diegosouzapw/OmniRoute/pull/2398))- **build(deps):** development group bumps — 4 updates. ([#2399](https://github.com/diegosouzapw/OmniRoute/pull/2399))- **chore:** sync `release/v3.8.0` with `main` (CodeQL hotfixes + Dependabot bumps) via merge commit.+- **fix(providers):** Kilo Code provider no longer blocks on a missing local `kilocode` CLI binary — the provider uses OAuth device flow + direct HTTPS to `api.kilo.ai` and never required the CLI at runtime; the connection test was hard-failing with "Local CLI runtime is not installed" even when the OAuth token was valid. CLI Tools integration (`/api/cli-tools/kilo-settings`) keeps its own runtime check. ([#2404](https://github.com/diegosouzapw/OmniRoute/issues/2404) — thanks @Flexible78)+- **fix(db):** `bun add -g omniroute` (and other runtimes that skip postinstall) no longer surfaces a generic 500 — `isNativeSqliteLoadError` now also detects "Could not locate the bindings file" / `MODULE_NOT_FOUND`, so the user gets the friendly rebuild guide instead. ([#2358](https://github.com/diegosouzapw/OmniRoute/issues/2358) — thanks @yamansin)### 🏆 v3.8.0 Hall of Fame — extended credits (post-release)diff --git a/src/lib/db/core.ts b/src/lib/db/core.tsindex f2ffcf8f9a..682795da1f 100644--- a/src/lib/db/core.ts+++ b/src/lib/db/core.ts@@ -89,13 +89,20 @@ const CRITICAL_DB_TABLES: CriticalTableSpec[] = [{ table: "webhooks", maxRows: 5_000 },];-function isNativeSqliteLoadError(error: unknown): boolean {+export function isNativeSqliteLoadError(error: unknown): boolean {const message = error instanceof Error ? error.message : String(error);+ const code = getErrorCode(error);return (message.includes("Module did not self-register") ||message.includes("NODE_MODULE_VERSION") ||message.includes("ERR_DLOPEN_FAILED") ||- getErrorCode(error) === "ERR_DLOPEN_FAILED"+ // bun and similar runtimes that skip the postinstall script never download+ // the prebuilt *.node binary, so `bindings()` fails with this message+ // before any DLOPEN even happens (#2358).+ message.includes("Could not locate the bindings file") ||+ message.includes("Cannot find module 'better-sqlite3'") ||+ code === "ERR_DLOPEN_FAILED" ||+ code === "MODULE_NOT_FOUND");}diff --git a/tests/unit/db-core-native-error.test.ts b/tests/unit/db-core-native-error.test.tsnew file mode 100644index 0000000000..ae836978fb--- /dev/null+++ b/tests/unit/db-core-native-error.test.ts@@ -0,0 +1,54 @@+import test from "node:test";+import assert from "node:assert/strict";++import { isNativeSqliteLoadError } from "../../src/lib/db/core";++test("isNativeSqliteLoadError detects Module did not self-register", () => {+ const err = new Error("Module did not self-register: better_sqlite3.node");+ assert.equal(isNativeSqliteLoadError(err), true);+});++test("isNativeSqliteLoadError detects NODE_MODULE_VERSION mismatch", () => {+ const err = new Error(+ "The module was compiled against a different Node.js version using NODE_MODULE_VERSION 115."+ );+ assert.equal(isNativeSqliteLoadError(err), true);+});++test("isNativeSqliteLoadError detects ERR_DLOPEN_FAILED in message", () => {+ const err = new Error("ERR_DLOPEN_FAILED while loading better_sqlite3.node");+ assert.equal(isNativeSqliteLoadError(err), true);+});++test("isNativeSqliteLoadError detects ERR_DLOPEN_FAILED via error.code", () => {+ const err = Object.assign(new Error("dlopen failed"), { code: "ERR_DLOPEN_FAILED" });+ assert.equal(isNativeSqliteLoadError(err), true);+});++// #2358 — bun and similar runtimes skip postinstall, so the *.node binary+// is never downloaded. `bindings()` produces this exact message before any+// DLOPEN even happens, and we need to surface the friendly rebuild guide.+test("isNativeSqliteLoadError detects 'Could not locate the bindings file' (bun #2358)", () => {+ const err = new Error(+ "Could not locate the bindings file. Tried: → /Users/x/.../better-sqlite3/build/better_sqlite3.node"+ );+ assert.equal(isNativeSqliteLoadError(err), true);+});++test("isNativeSqliteLoadError detects 'Cannot find module better-sqlite3'", () => {+ const err = new Error("Cannot find module 'better-sqlite3'");+ assert.equal(isNativeSqliteLoadError(err), true);+});++test("isNativeSqliteLoadError detects MODULE_NOT_FOUND via error.code", () => {+ const err = Object.assign(new Error("not found"), { code: "MODULE_NOT_FOUND" });+ assert.equal(isNativeSqliteLoadError(err), true);+});++test("isNativeSqliteLoadError returns false for unrelated errors", () => {+ assert.equal(isNativeSqliteLoadError(new Error("SQLITE_BUSY: database is locked")), false);+ assert.equal(isNativeSqliteLoadError(new Error("ENOENT: no such file")), false);+ assert.equal(isNativeSqliteLoadError(null), false);+ assert.equal(isNativeSqliteLoadError(undefined), false);+ assert.equal(isNativeSqliteLoadError("some string"), false);+});