{"record":{"id":"80d23566a9418bd9","repo":"usebruno/bruno","slug":"single-object-export-requires-exactly-one-environm","errorCode":null,"errorMessage":"Single object export requires exactly one environment","messagePattern":"Single object export requires exactly one environment","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/bruno-electron/src/ipc/collection.js","lineNumber":1027,"sourceCode":"        const baseFileName = `bruno-${environmentType}-environments`;\n        const uniqueFileName = generateUniqueName(baseFileName, (name) => fs.existsSync(path.join(filePath, `${name}.json`)));\n        const fullPath = path.join(filePath, `${uniqueFileName}.json`);\n\n        const exportData = {\n          info: {\n            type: 'bruno-environment',\n            exportedAt: new Date().toISOString(),\n            exportedUsing: `Bruno/v${appVersion}`\n          },\n          environments\n        };\n\n        const jsonContent = JSON.stringify(exportData, null, 2);\n        await fs.promises.writeFile(fullPath, jsonContent, 'utf8');\n      } else if (exportFormat === 'single-object') {\n        // single environment json file\n        if (environments.length !== 1) {\n          throw new Error('Single object export requires exactly one environment');\n        }\n\n        const environment = environments[0];\n        const baseFileName = environment.name ? `${environment.name.replace(/[^a-zA-Z0-9-_]/g, '_')}` : 'environment';\n        const uniqueFileName = generateUniqueName(baseFileName, (name) => fs.existsSync(path.join(filePath, `${name}.json`)));\n        const fullPath = path.join(filePath, `${uniqueFileName}.json`);\n        const jsonContent = JSON.stringify(environmentWithInfo(environment), null, 2);\n        await fs.promises.writeFile(fullPath, jsonContent, 'utf8');\n      } else {\n        throw new Error(`Unsupported export format: ${exportFormat}`);\n      }\n    } catch (error) {\n      return Promise.reject(error);\n    }\n  });\n\n  // rename item\n  ipcMain.handle('renderer:rename-item-name', async (event, { itemPath, newName, collectionPathname }) => {","sourceCodeStart":1009,"sourceCodeEnd":1045,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/collection.js#L1009-L1045","documentation":"Thrown by 'renderer:export-environment' when exportFormat is 'single-object' but the environments array does not have exactly one entry. The single-object format writes one JSON file representing one environment, so zero or multiple environments are rejected.","triggerScenarios":"Selecting 'single object' export with a multi-select of environments, or with none selected; passing an array of length 0 or >= 2 with exportFormat: 'single-object'.","commonSituations":"UI exposes a 'select all + single-file' combination, batch export menu defaults to multi-select, or the user changed selection after picking the format.","solutions":["Switch the user to 'folder' export when more than one environment is selected.","Disable the single-object option in the UI unless exactly one environment is selected.","Reduce the selection to one environment before invoking."],"exampleFix":"// before\nawait window.Ipc.invoke('renderer:export-environment', { environments: allEnvs, environmentType, filePath, exportFormat: 'single-object' });\n\n// after\nconst fmt = selectedEnvs.length === 1 ? 'single-object' : 'folder';\nawait window.Ipc.invoke('renderer:export-environment', { environments: selectedEnvs, environmentType, filePath, exportFormat: fmt });","handlingStrategy":"validation","validationCode":"if (exportFormat === 'single-object' && environments.length !== 1) {\n  throw new Error('Select exactly one environment for single-object export');\n}\nawait window.Ipc.invoke('renderer:export-environment', { environments, environmentType, filePath, exportFormat });","typeGuard":"function canSingleObjectExport(environments: unknown[], fmt: string): boolean {\n  return fmt !== 'single-object' || (Array.isArray(environments) && environments.length === 1);\n}","tryCatchPattern":null,"preventionTips":["Disable 'single-object' in the UI unless exactly one environment is selected.","Default to 'folder' export for multi-select.","Validate selection size before opening the format picker."],"tags":["ipc","export","validation","environment"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}