@threadbase-sh/scanner 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1960,7 +1960,13 @@ function openDatabase(dbPath) {
1960
1960
  if (dbPath !== ":memory:") {
1961
1961
  mkdirSync(dirname3(dbPath), { recursive: true });
1962
1962
  }
1963
- const db = new Database(dbPath);
1963
+ let db;
1964
+ try {
1965
+ db = new Database(dbPath);
1966
+ } catch (err) {
1967
+ if (isNativeBindingFailure(err)) throw nativeBindingError(err, dbPath);
1968
+ throw err;
1969
+ }
1964
1970
  db.pragma("journal_mode = WAL");
1965
1971
  db.pragma("synchronous = NORMAL");
1966
1972
  db.pragma("temp_store = MEMORY");
@@ -1970,6 +1976,30 @@ function openDatabase(dbPath) {
1970
1976
  getLogger().debug({ dbPath }, "db: opened");
1971
1977
  return db;
1972
1978
  }
1979
+ function isNativeBindingFailure(err) {
1980
+ const message = err instanceof Error ? err.message : String(err);
1981
+ return /could not locate the bindings file|NODE_MODULE_VERSION|was compiled against|\.node['"\s]/i.test(
1982
+ message
1983
+ );
1984
+ }
1985
+ function nativeBindingError(err, dbPath) {
1986
+ const detail = err instanceof Error ? err.message : String(err);
1987
+ return new Error(
1988
+ [
1989
+ `Could not load better-sqlite3's native binary, so the persistent index at ${dbPath} cannot be opened.`,
1990
+ "This usually means the binary was never built or downloaded \u2014 not that your Node version is wrong.",
1991
+ "",
1992
+ "Try, in order:",
1993
+ " 1. npm rebuild better-sqlite3",
1994
+ " 2. rm -rf node_modules && npm install",
1995
+ " (npm 12 blocks package install scripts by default; approve better-sqlite3 if asked)",
1996
+ " 3. Run without SQLite entirely: new ConversationScanner({ persistent: false })",
1997
+ " or pass --no-persist on the CLI. Search falls back to the in-memory index.",
1998
+ "",
1999
+ `Original error: ${detail}`
2000
+ ].join("\n")
2001
+ );
2002
+ }
1973
2003
 
1974
2004
  // src/persistent/dir-watermark.ts
1975
2005
  import { readdir, stat as stat3 } from "fs/promises";