{"record":{"id":"fac397f951ae1ea2","repo":"usebruno/bruno","slug":"collection-not-found-in-workspace","errorCode":null,"errorMessage":"Collection not found in workspace","messagePattern":"Collection not found in workspace","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-electron/src/utils/workspace-config.js","lineNumber":461,"sourceCode":"const setCollectionGitRemote = async (workspacePath, collectionPath, remoteUrl) => {\n  if (typeof remoteUrl !== 'string' || remoteUrl.trim() === '') {\n    throw new Error('A non-empty Git remote URL is required');\n  }\n  const trimmedUrl = remoteUrl.trim();\n\n  return withLock(getWorkspaceLockKey(workspacePath), async () => {\n    const config = readWorkspaceConfig(workspacePath);\n    const target = path.normalize(collectionPath);\n    let matched = false;\n\n    config.collections = (config.collections || []).map((c) => {\n      if (getNormalizedAbsoluteCollectionPath(workspacePath, c) !== target) return c;\n      matched = true;\n      return { ...c, remote: trimmedUrl };\n    });\n\n    if (!matched) {\n      throw new Error('Collection not found in workspace');\n    }\n\n    await writeWorkspaceFileAtomic(workspacePath, generateYamlContent(config));\n    await addCollectionToWorkspaceGitignore(workspacePath, collectionPath);\n    return config;\n  });\n};\n\nconst clearCollectionGitRemote = async (workspacePath, collectionPath) => {\n  return withLock(getWorkspaceLockKey(workspacePath), async () => {\n    const config = readWorkspaceConfig(workspacePath);\n    const target = path.normalize(collectionPath);\n    let matched = false;\n\n    config.collections = (config.collections || []).map((c) => {\n      if (getNormalizedAbsoluteCollectionPath(workspacePath, c) !== target) return c;\n      matched = true;\n      const updated = { ...c };","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/utils/workspace-config.js#L443-L479","documentation":"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.","triggerScenarios":"Calling `setCollectionGitRemote` with a `collectionPath` that does not match any collection's resolved absolute path in the workspace config.","commonSituations":"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.","solutions":["Pass the exact absolute collection path as resolved by the workspace.","Re-read the workspace collections and use a returned path verbatim.","Confirm the collection still exists in `workspace.yml` before setting its remote.","Normalize the path with `path.normalize` to match the comparison."],"exampleFix":"// before\nawait setCollectionGitRemote(wsPath, 'api', url);   // relative, never matches\n\n// after\nawait setCollectionGitRemote(wsPath, path.join(wsPath, 'api'), url);","handlingStrategy":"validation","validationCode":"const path = require('path');\nfunction resolveCollectionForRemote(config, wsPath, colPath) {\n  const target = path.normalize(colPath);\n  return (config.collections || []).find(c =>\n    path.normalize(path.resolve(wsPath, c.path)) === target);\n}\nif (!resolveCollectionForRemote(config, wsPath, colPath)) {\n  throw new Error('Collection not found in workspace');\n}","typeGuard":null,"tryCatchPattern":"try { await setCollectionGitRemote(wsPath, colPath, url); }\ncatch (e) { if (/Collection not found/.test(e.message)) { /* refresh list, retry */ } else throw e; }","preventionTips":["Pass absolute, normalized collection paths.","Refresh the workspace collection list before remote operations."],"tags":["workspace","collection","git","validation"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}