Skip to content

qmd search --json outputs plain text instead of [] when no results found #183

@IntegratedLiving

Description

@IntegratedLiving

Bug

When qmd search --json "<query>" returns zero results, it outputs the plain text string "No results found." instead of an empty JSON array [].

This breaks any caller that expects valid JSON output when --json is specified.

Steps to Reproduce

  1. Run qmd search --json "some query that returns no results"
  2. Observe stdout is No results found. (plain text)
  3. Expected: [] (valid empty JSON array)

Root Cause

In src/qmd.ts (~line 1892), the empty results check prints plain text without checking the format flag:

if (resultsWithContext.length === 0) {
    console.log("No results found.");  // ignores opts.format
    return;
}

Suggested Fix

if (resultsWithContext.length === 0) {
    if (opts.format === "json") console.log("[]");
    else console.log("No results found.");
    return;
}

Impact

When QMD is used as a memory backend (e.g. via OpenClaw), the caller does JSON.parse(stdout) which throws on "No results found.". In our case this triggered a fallback to a 300MB CPU-based embedding model, causing ~2.5 minute delays on every empty-result query.

Environment

  • QMD v1.0.0
  • Runtime: Bun 1.3.9
  • OS: Ubuntu 24.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions