tobi/qmd · error · Error

Failed to parse ${configPath}: ${error}

Error message

Failed to parse ${configPath}: ${error}

What it means

loadConfig failed while reading the QMD YAML config file. The file exists but its contents could not be parsed as YAML (or the parsed result was unusable), so the raw parser error is wrapped with the offending path. This is thrown from loadConfig, which backs config loading for the CLI and createStore.

Source

Thrown at src/collections.ts:202

  // File-based config (SDK custom path or default)
  const configPath = configSource.path || getConfigFilePath();
  if (!existsSync(configPath)) {
    return { collections: {} };
  }

  try {
    const content = readFileSync(configPath, "utf-8");
    const parsed = YAML.parse(content) as CollectionConfig | null | undefined;
    const config = parsed ?? { collections: {} };

    // Ensure collections object exists
    if (!config.collections) {
      config.collections = {};
    }

    return config;
  } catch (error) {
    throw new Error(`Failed to parse ${configPath}: ${error}`);
  }
}

/**
 * Save configuration to the configured source.
 * - Inline config: updates the in-memory object (no file I/O)
 * - File-based: writes to YAML file (default ~/.config/qmd/index.yml)
 */
export function saveConfig(config: CollectionConfig): void {
  // SDK inline config mode: update in place, no file I/O
  if (configSource.type === 'inline') {
    configSource.config = config;
    return;
  }

  const configPath = configSource.path || getConfigFilePath();
  const configDir = dirname(configPath);
  if (!existsSync(configDir)) {

View on GitHub (pinned to dbfd0b4736)

Solutions

  1. Run `qmd doctor` to diagnose config issues
  2. Inspect the file named in the message with a YAML linter and fix indentation/quotes
  3. If unsure, delete the corrupt config and regenerate with `qmd collection add` or `qmd init`
  4. Keep configs out of manual edits; use qmd CLI commands to mutate them

Example fix

# before (broken)
collections:
  notes:
  path: ~/notes   # bad indentation
# after
collections:
  notes:
    path: ~/notes
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync } from 'node:fs';
import { parse } from 'yaml';

function configLooksValid(configPath: string): boolean {
  try { parse(readFileSync(configPath, 'utf-8')); return true; }
  catch { return false; }
}

Try / catch

try {
  const store = await createStore({ dbPath, configPath });
} catch (e) {
  if (e instanceof Error && e.message.startsWith('Failed to parse')) {
    console.error('Config syntax error:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling createStore({configPath: './qmd.yaml'}) or any qmd CLI command when the YAML config has a syntax error: bad indentation, unclosed quote, tabs, or pasted markdown mixed into the YAML.

Common situations: Hand-editing ~/.config/qmd/config.yaml or a project .qmd config and breaking YAML syntax; merging config changes via git producing conflicts left in the file; empty file with invalid BOM or non-UTF8 bytes.

Understand the failure class

Related errors


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