can1357/oh-my-pi · error · ToolError

SQLite query parameter 'q' cannot be empty

Error message

SQLite query parameter 'q' cannot be empty

What it means

Thrown when the 'q' parameter is present but empty or whitespace-only. An empty raw query has no meaning, so the parser rejects it explicitly instead of issuing a useless query to SQLite.

Source

Thrown at packages/coding-agent/src/tools/sqlite-reader.ts:572

	try {
		return looksLikeSqlite(await Bun.file(absolutePath).slice(0, SQLITE_MAGIC.byteLength).bytes());
	} catch {
		return false;
	}
}

export function parseSqliteSelector(subPath: string, queryString: string): SqliteSelector {
	const normalizedSubPath = subPath.replace(/^:+/, "").trim();
	const params = new URLSearchParams(queryString);
	const rawQuery = params.get("q");

	if (rawQuery !== null) {
		const otherKeys = [...params.keys()].filter(key => key !== "q");
		if (normalizedSubPath || otherKeys.length > 0) {
			throw new ToolError("SQLite raw queries cannot be combined with table selectors or pagination");
		}
		if (!rawQuery.trim()) {
			throw new ToolError("SQLite query parameter 'q' cannot be empty");
		}
		return { kind: "raw", sql: rawQuery };
	}

	if (!normalizedSubPath) {
		if (params.size > 0) {
			throw new ToolError("SQLite query parameters require a table selector or q=SELECT...");
		}
		return { kind: "list" };
	}

	const separatorIndex = normalizedSubPath.indexOf(":");
	const table = separatorIndex === -1 ? normalizedSubPath : normalizedSubPath.slice(0, separatorIndex);
	const key = separatorIndex === -1 ? undefined : normalizedSubPath.slice(separatorIndex + 1);
	if (!table) {
		throw new ToolError("SQLite selectors must include a table name");
	}

View on GitHub (pinned to 9690622007)

Solutions

  1. Provide a non-empty SQL statement in q
  2. Omit the q param entirely if you meant to use the table/list API
  3. Check upstream code for empty-string defaults overwriting the query

Example fix

// before
const url = `db.sqlite?q=${sql.trim()}` // sql was empty
// after
if (!sql.trim()) throw new Error('sql required');
const url = `db.sqlite?q=${encodeURIComponent(sql)}`
Defensive patterns

Strategy: validation

Validate before calling

if (q != null && !q.trim()) {
  throw new Error('q param present but empty; provide SQL or omit q');
}

Try / catch

try {
  await reader.read(`db.sqlite?q=${encodeURIComponent(q)}`);
} catch (err) {
  if (err instanceof ToolError && err.message.includes("'q' cannot be empty")) {
    // skip the call or surface a 'no query provided' state
  } else throw err;
}

Prevention

When it happens

Trigger: URLs like 'db.sqlite?q=' or 'db.sqlite?q=%20%20'; an upstream variable holding the SQL being empty; template interpolation producing a blank q value.

Common situations: Optional SQL variable that came through as empty string; form/UI field left blank; trimmed-out query after sanitization upstream.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/8f058b5f0b315e3d. Report an issue: GitHub.