can1357/oh-my-pi · error · FileNotFoundError
Database not found: ${sourcePath}
Error message
Database not found: ${sourcePath} What it means
createBackup snapshots the SQLite database at sourcePath (falling back to the configured default db path). Before doing anything it checks existence and throws FileNotFoundError when the source database file is missing, so a backup is never created from a nonexistent database.
Source
Thrown at packages/mnemopi/src/dr/recovery.ts:149
const explicit = env.MNEMOPI_BACKUP_DIR;
if (explicit !== undefined && explicit.length > 0) return explicit;
const dir = configuredDataDir(env);
return join(dirname(dir), "backups");
}
export function getDefaultPaths(env: Env = process.env): RecoveryPaths {
return {
dataDir: configuredDataDir(env),
backupDir: defaultBackupDir(env),
dbPath: configuredDbPath(env),
};
}
export function createBackup(dbPath?: string | null, backupDir?: string | null): BackupResult {
const paths = getDefaultPaths();
const sourcePath = dbPath ?? paths.dbPath;
const destinationDir = backupDir ?? paths.backupDir;
if (!existsSync(sourcePath)) throw new FileNotFoundError(`Database not found: ${sourcePath}`);
mkdirSync(destinationDir, { recursive: true });
const timestamp = timestampForBackup();
let snapshot: Uint8Array | null = null;
let sourceDb: Database | null = null;
try {
sourceDb = openDatabase(sourcePath, { create: false, readwrite: false, pragmas: false });
snapshot = (sourceDb as SerializableDatabase).serialize();
} finally {
closeQuietly(sourceDb);
}
if (snapshot === null) throw new Error(`Unable to serialize database backup: ${sourcePath}`);
const backupPath = writeBackupFile(destinationDir, timestamp, gzipSync(snapshot));
const dbBytes = readFileSync(sourcePath);
const backupBytes = readFileSync(backupPath);
const metadata: BackupMetadata = {View on GitHub (pinned to 9690622007)
Solutions
- Verify the db file exists at the path (ls / existsSync) and fix the path argument
- Create/initialize the database first (open it once so the file exists), then back up
- Check MNEMOPI config/default paths — pass an explicit dbPath rather than relying on defaults
Example fix
// before
createBackup("./data/memry.db"); // typo
// after
const dbPath = "./data/memory.db";
if (!existsSync(dbPath)) throw new Error(`db missing: ${dbPath}`);
createBackup(dbPath, backupDir); Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from "node:fs";
function safeCreateBackup(dbPath, backupDir) {
if (!existsSync(dbPath)) throw new Error(`refusing backup: db missing at ${dbPath}`);
return createBackup(dbPath, backupDir);
} Try / catch
try {
createBackup(dbPath, backupDir);
} catch (err) {
if (err.name === "FileNotFoundError" && err.message.startsWith("Database not found")) {
initDatabase(dbPath); // create + seed the db, then retry once
createBackup(dbPath, backupDir);
} else throw err;
} Prevention
- Resolve db paths to absolute paths once at startup
- Initialize the database before enabling backup jobs
- Validate configured paths exist at boot
- Use try/catch with isEnoent rather than manual existence checks when reading
When it happens
Trigger: createBackup(path) with a typo'd or moved db file; calling backup before the database was ever created (fresh install); pointing at the wrong environment's path (staging vs prod); dbPath param explicitly null while the default path doesn't exist.
Common situations: First run before any write created the db; container/volume remounts losing the data dir; relative vs absolute path confusion after changing working directory; deleted db while the app was stopped.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- backing up {} might destroy source; {} not moved
- File not found: ${path}
- Local file not found: ${url.href}
- File not found: ${resolvedPath}
- File not found: ${targetPath}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/397b106036b04f08.
Report an issue: GitHub.