usebruno/bruno · error · Error

Collection not found in workspace

Error message

Collection not found in workspace

What it means

Inside `setCollectionGitRemote`, after iterating collections and matching by normalized absolute path, if no collection equaled `path.normalize(collectionPath)` the `matched` flag stays false and this is thrown before writing.

Source

Thrown at packages/bruno-electron/src/utils/workspace-config.js:461

const setCollectionGitRemote = async (workspacePath, collectionPath, remoteUrl) => {
  if (typeof remoteUrl !== 'string' || remoteUrl.trim() === '') {
    throw new Error('A non-empty Git remote URL is required');
  }
  const trimmedUrl = remoteUrl.trim();

  return withLock(getWorkspaceLockKey(workspacePath), async () => {
    const config = readWorkspaceConfig(workspacePath);
    const target = path.normalize(collectionPath);
    let matched = false;

    config.collections = (config.collections || []).map((c) => {
      if (getNormalizedAbsoluteCollectionPath(workspacePath, c) !== target) return c;
      matched = true;
      return { ...c, remote: trimmedUrl };
    });

    if (!matched) {
      throw new Error('Collection not found in workspace');
    }

    await writeWorkspaceFileAtomic(workspacePath, generateYamlContent(config));
    await addCollectionToWorkspaceGitignore(workspacePath, collectionPath);
    return config;
  });
};

const clearCollectionGitRemote = async (workspacePath, collectionPath) => {
  return withLock(getWorkspaceLockKey(workspacePath), async () => {
    const config = readWorkspaceConfig(workspacePath);
    const target = path.normalize(collectionPath);
    let matched = false;

    config.collections = (config.collections || []).map((c) => {
      if (getNormalizedAbsoluteCollectionPath(workspacePath, c) !== target) return c;
      matched = true;
      const updated = { ...c };

View on GitHub (pinned to 9bdd81c7bd)

Solutions

  1. Pass the exact absolute collection path as resolved by the workspace.
  2. Re-read the workspace collections and use a returned path verbatim.
  3. Confirm the collection still exists in `workspace.yml` before setting its remote.
  4. Normalize the path with `path.normalize` to match the comparison.

Example fix

// before
await setCollectionGitRemote(wsPath, 'api', url);   // relative, never matches

// after
await setCollectionGitRemote(wsPath, path.join(wsPath, 'api'), url);
Defensive patterns

Strategy: validation

Validate before calling

const path = require('path');
function resolveCollectionForRemote(config, wsPath, colPath) {
  const target = path.normalize(colPath);
  return (config.collections || []).find(c =>
    path.normalize(path.resolve(wsPath, c.path)) === target);
}
if (!resolveCollectionForRemote(config, wsPath, colPath)) {
  throw new Error('Collection not found in workspace');
}

Try / catch

try { await setCollectionGitRemote(wsPath, colPath, url); }
catch (e) { if (/Collection not found/.test(e.message)) { /* refresh list, retry */ } else throw e; }

Prevention

When it happens

Trigger: Calling `setCollectionGitRemote` with a `collectionPath` that does not match any collection's resolved absolute path in the workspace config.

Common situations: Path separator mismatch (Windows backslash vs forward slash); relative path passed where absolute expected (or vice versa); the collection was removed; collectionPath from a stale UI list; trailing slash differences.

Related errors


AI-assisted analysis of usebruno/bruno@9bdd81c7bd (2026-08-13). Data as JSON: /api/errors/fac397f951ae1ea2. Report an issue: GitHub.