tobi/qmd · error · Error

dbPath is required

Error message

dbPath is required

What it means

createStore validates its options and requires dbPath, the SQLite database location. Without it the store has nowhere to open/create the index, so it fails fast before touching the filesystem.

Source

Thrown at src/index.ts:354

 * })
 *
 * // With inline config (no files needed besides the DB)
 * const store = await createStore({
 *   dbPath: './index.sqlite',
 *   config: {
 *     collections: {
 *       docs: { path: '/path/to/docs', pattern: '**\/*.md' }
 *     }
 *   }
 * })
 *
 * const results = await store.search({ query: "authentication flow" })
 * await store.close()
 * ```
 */
export async function createStore(options: StoreOptions): Promise<QMDStore> {
  if (!options.dbPath) {
    throw new Error("dbPath is required");
  }
  if (options.configPath && options.config) {
    throw new Error("Provide either configPath or config, not both");
  }

  // Create the internal store (opens DB, creates tables)
  const internal = createStoreInternal(options.dbPath);
  const db = internal.db;

  // Track whether we have a YAML config path for write-through
  const hasYamlConfig = !!options.configPath;

  // Sync config into SQLite store_collections
  let config: CollectionConfig | undefined;
  if (options.configPath) {
    // YAML mode: inject config source for write-through, sync to DB
    setConfigSource({ configPath: options.configPath });
    config = loadConfig();

View on GitHub (pinned to dbfd0b4736)

Solutions

  1. Supply options.dbPath, e.g. createStore({dbPath: '~/.cache/qmd/index.sqlite', configPath: './qmd.yaml'})
  2. Check for typos in the option name
  3. Default dbPath from an env var: process.env.QMD_DB ?? fallback

Example fix

// before
const store = await createStore({ configPath: './qmd.yaml' });
// after
const store = await createStore({
  dbPath: './qmd-index.sqlite',
  configPath: './qmd.yaml',
});
Defensive patterns

Strategy: validation

Validate before calling

function assertStoreOptions(o: StoreOptions): asserts o is StoreOptions & { dbPath: string } {
  if (!o.dbPath) throw new Error('dbPath is required');
}

Type guard

const hasDbPath = (o: StoreOptions): o is StoreOptions & { dbPath: string } =>
  typeof o.dbPath === 'string' && o.dbPath.length > 0;

Prevention

When it happens

Trigger: Calling createStore({}) or createStore({configPath: './qmd.yaml'}) with no dbPath; passing a mistyped key like dbpath or path.

Common situations: Quick integrations copying example code but omitting dbPath; refactors renaming StoreOptions fields; passing options built from an env var that is undefined.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of tobi/qmd@dbfd0b4736 (2026-08-28). Data as JSON: /api/errors/a67d9eef884f6237. Report an issue: GitHub.