tobi/qmd · error · Error
Collection '${newName}' already exists
Error message
Collection '${newName}' already exists What it means
renameCollection refuses to rename a collection because the target name already exists in the config, which would silently overwrite its settings. The check runs after confirming the old name exists, so this indicates a genuine collision, not a missing source.
Source
Thrown at src/collections.ts:352
}
delete config.collections[name];
saveConfig(config);
return true;
}
/**
* Rename a collection
*/
export function renameCollection(oldName: string, newName: string): boolean {
const config = loadConfig();
if (!config.collections[oldName]) {
return false;
}
if (config.collections[newName]) {
throw new Error(`Collection '${newName}' already exists`);
}
config.collections[newName] = config.collections[oldName];
delete config.collections[oldName];
saveConfig(config);
return true;
}
// ============================================================================
// Context management
// ============================================================================
/**
* Get global context
*/
export function getGlobalContext(): string | undefined {
const config = loadConfig();
return config.global_context;View on GitHub (pinned to dbfd0b4736)
Solutions
- Choose a different new name, or first remove the existing collection: qmd collection remove <newName> then retry the rename
- List collections with `qmd collection list` to confirm which names are taken
- If the existing target is stale, rename or remove it first
Defensive patterns
Strategy: validation
Validate before calling
// Before renaming, check target availability
import { loadConfig } from './src/collections.js';
const config = loadConfig(configPath);
const targetFree = !config.collections?.[newName]; Try / catch
try {
ok = renameCollection(oldName, newName);
} catch (e) {
if (e instanceof Error && /already exists/.test(e.message)) {
// pick another name or remove existing first
} else throw e;
} Prevention
- List collections with `qmd collection list` before renaming
- Make rename scripts idempotent: check target first
- Avoid rename targets similar to existing names
When it happens
Trigger: Calling qmd collection rename mynotes notes when a collection named notes already exists; calling renameCollection('a','b') programmatically where both keys are present.
Common situations: Re-running a rename script that partially completed; renaming to a name you forgot you created earlier; shell completion picking an existing name.
Related errors
AI-assisted analysis of tobi/qmd@dbfd0b4736 (2026-08-28).
Data as JSON: /api/errors/1164fc3ec56aeb14.
Report an issue: GitHub.