dmtrKovalenko/fff · error

Failed to init frecency db

Error message

Failed to init frecency db: {}

What it means

FrecencyTracker::open failed to open or create the LMDB frecency database at frecency_db_path. The LMDB error is embedded in the message. Without the frecency db, ranking data cannot load, so instance creation fails.

Solutions

  1. Ensure the directory for frecency_db_path exists and is writable (library creates parents but check permissions).
  2. Delete the corrupted LMDB files (data.mdb/lock.mdb) so they are recreated — frecency data is rebuildable cache.
  3. Stop other processes holding the db lock, then retry.
  4. Point frecency_db_path at a fresh writable location to confirm it is a path/permission issue.
  5. Check free disk space.

Example fix

// before
opts.frecency_db_path = "/root/.cache/fff/frecency"; // no permission
// after
opts.frecency_db_path = "/home/me/.cache/fff/frecency"; // or rm corrupted *.mdb files
Defensive patterns

Strategy: fallback

Validate before calling

const fs = require('fs');
if (frecencyPath) { fs.mkdirSync(path.dirname(frecencyPath), { recursive: true }); fs.accessSync(path.dirname(frecencyPath), fs.constants.W_OK); }

Try / catch

try {
  createInstance({ ...opts, frecency_db_path: p });
} catch (e) {
  if (/Failed to init frecency db/.test(e.message)) {
    fs.rmSync(p, { recursive: true, force: true }); // clear corrupt LMDB cache
    return createInstance({ ...opts, frecency_db_path: p });
  }
  throw e;
}

Prevention

When it happens

Trigger: frecency_db_path points to a non-existent, unwritable directory; the db file is corrupted or locked by another process; parent directory creation failed; invalid path syntax.

Common situations: Read-only home/cache directories (containers, CI); a stale or corrupted data.mdb/lock.mdb after a crash; two different library versions sharing one db file; full disk.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of dmtrKovalenko/fff@7f8537e70f (2026-09-10). Data as JSON: /api/errors/4542a92b9e11cdec. Report an issue: GitHub.

Appendix: source

Thrown at crates/fff-c/src/lib.rs:225

    let frecency_path = unsafe { optional_cstr(opts.frecency_db_path) }.map(|s| s.to_string());
    let history_path = unsafe { optional_cstr(opts.history_db_path) }.map(|s| s.to_string());

    let shared_picker = SharedFilePicker::default();
    let shared_frecency = SharedFrecency::default();
    let query_tracker = SharedQueryTracker::default();

    if let Some(ref frecency_path) = frecency_path {
        if let Some(parent) = PathBuf::from(frecency_path).parent() {
            let _ = std::fs::create_dir_all(parent);
        }

        match FrecencyTracker::open(frecency_path) {
            Ok(tracker) => {
                if let Err(e) = shared_frecency.init(tracker) {
                    return FffResult::err(&format!("Failed to acquire frecency lock: {}", e));
                }
            }
            Err(e) => return FffResult::err(&format!("Failed to init frecency db: {}", e)),
        }
    }

    if let Some(ref history_path) = history_path {
        if let Some(parent) = PathBuf::from(history_path).parent() {
            let _ = std::fs::create_dir_all(parent);
        }

        match QueryTracker::open(history_path) {
            Ok(tracker) => {
                if let Err(e) = query_tracker.init(tracker) {
                    return FffResult::err(&format!("Failed to acquire query tracker lock: {}", e));
                }
            }
            Err(e) => return FffResult::err(&format!("Failed to init query tracker db: {}", e)),
        }
    }

View on GitHub (pinned to 7f8537e70f)