{"record":{"id":"ee66724429811eab","repo":"usebruno/bruno","slug":"could-not-determine-collection-for-target-director","errorCode":null,"errorMessage":"Could not determine collection for target directory","messagePattern":"Could not determine collection for target directory","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-electron/src/ipc/collection.js","lineNumber":598,"sourceCode":"      return Promise.reject(error);\n    }\n  });\n\n  ipcMain.handle('renderer:save-transient-request', async (event, { sourcePathname, targetDirname, targetFilename, request, format, sourceFormat }) => {\n    try {\n      if (!fs.existsSync(sourcePathname)) {\n        throw new Error(`Source path: ${sourcePathname} does not exist`);\n      }\n\n      if (!fs.existsSync(targetDirname)) {\n        throw new Error(`Target directory: ${targetDirname} does not exist`);\n      }\n\n      validatePathIsInsideCollection(targetDirname);\n\n      const collectionPath = findCollectionPathByItemPath(targetDirname);\n      if (!collectionPath) {\n        throw new Error('Could not determine collection for target directory');\n      }\n      const targetFormat = getCollectionFormat(collectionPath);\n\n      const filename = targetFilename || path.basename(sourcePathname);\n      const filenameWithoutExt = filename.replace(/\\.(bru|yml)$/, '');\n      const finalFilename = `${filenameWithoutExt}.${targetFormat}`;\n      const targetPathname = path.join(targetDirname, finalFilename);\n\n      if (fs.existsSync(targetPathname)) {\n        throw new Error(`A file with the name \"${finalFilename}\" already exists in the target location`);\n      }\n\n      const actualSourceFormat = sourceFormat || 'yml';\n      const needsConversion = actualSourceFormat !== targetFormat;\n\n      let finalContent;\n      if (needsConversion) {\n        const { parseRequest, stringifyRequest } = require('@usebruno/filestore');","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/collection.js#L580-L616","documentation":"Thrown by 'renderer:save-transient-request' when findCollectionPathByItemPath(targetDirname) returns null. That helper walks every path registered with the collection watcher (sorted deepest-first) and returns the first whose normalized form is an ancestor of the target. Null means targetDirname is not inside any open/watched collection.","triggerScenarios":"Passing a targetDirname outside the collection root (absolute path to another drive, temp dir, or sibling directory). Saving into a collection that was closed/removed from the watcher. Path casing/separator differences on Windows/WSL that defeat the startsWith check.","commonSituations":"Target directory lives in a scratch/temp area not opened as a collection. Collection was closed in another window. WSL2 vs Windows path mismatch (e.g. /mnt/c vs C:\\).","solutions":["Ensure the collection containing targetDirname is opened and registered with the watcher before saving.","Pass a targetDirname that is genuinely inside an open collection root.","Normalize path separators (path.normalize) on the caller side to match the watcher's stored form.","If using WSL, resolve the path to the same representation Bruno uses for the collection root."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const collectionPath = await window.ipcRenderer.invoke('renderer:resolve-collection-for-path', targetDirname);\nif (!collectionPath) {\n  // open the collection containing targetDirname first, or pick a target inside an open collection\n}","typeGuard":null,"tryCatchPattern":"try {\n  await window.ipcRenderer.invoke('renderer:save-transient-request', payload);\n} catch (e) {\n  if (/Could not determine collection/.test(e.message)) {\n    await window.ipcRenderer.invoke('renderer:open-collection', pathToCollectionRoot);\n    await window.ipcRenderer.invoke('renderer:save-transient-request', payload);\n  } else throw e;\n}","preventionTips":["Only save into directories that live under an open collection root.","Normalize path separators (path.normalize) and reconcile WSL/Windows forms before sending.","Reopen the collection if it was closed in another window."],"tags":["ipc","filesystem","collection","path-traversal","bruno"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}