{"record":{"id":"14687ac77c74b1f6","repo":"usebruno/bruno","slug":"filename-file-already-exists-14687a","errorCode":null,"errorMessage":"${filename} file already exists","messagePattern":"(.+?) file already exists","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/bruno-electron/src/ipc/global-environments.js","lineNumber":220,"sourceCode":"      return Promise.reject(error);\n    }\n  });\n\n  // Create workspace .env file\n  ipcMain.handle('renderer:create-workspace-dotenv-file', async (event, { workspacePath, filename = '.env' }) => {\n    try {\n      if (!workspacePath) {\n        throw new Error('Workspace path is required');\n      }\n\n      if (!isValidDotEnvFilename(filename)) {\n        throw new Error('Invalid .env filename');\n      }\n\n      const dotEnvPath = path.join(workspacePath, filename);\n\n      if (fs.existsSync(dotEnvPath)) {\n        throw new Error(`${filename} file already exists`);\n      }\n\n      await writeFile(dotEnvPath, '');\n\n      return { success: true };\n    } catch (error) {\n      console.error('Error creating workspace .env file:', error);\n      return Promise.reject(error);\n    }\n  });\n\n  // Delete workspace .env file\n  ipcMain.handle('renderer:delete-workspace-dotenv-file', async (event, { workspacePath, filename = '.env' }) => {\n    try {\n      if (!workspacePath) {\n        throw new Error('Workspace path is required');\n      }\n","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/global-environments.js#L202-L238","documentation":"In `renderer:create-workspace-dotenv-file`, after validation passes, `fs.existsSync(dotEnvPath)` is checked. If the file is already present the handler refuses - create means create, it will not overwrite an existing env file.","triggerScenarios":"User clicks Create when `.env` (or the named variant) already exists in the workspace; a previous create left the file; a concurrent double-submit.","commonSituations":"The file is hidden in the UI so the user doesn't realize it exists; re-running create after a partial run.","solutions":["Use the save/edit flow (save-workspace-dotenv-raw) instead of create when the file exists.","Delete the existing file first if you truly want to recreate it.","Check existence in the UI and hide or disable Create when present."],"exampleFix":"// before\nawait invoke('renderer:create-workspace-dotenv-file', { workspacePath, filename: '.env' }); // throws if exists\n// after - edit instead of create\nawait invoke('renderer:save-workspace-dotenv-raw', { workspacePath, content: '', filename: '.env' });","handlingStrategy":"validation","validationCode":"const fs = require('fs'), path = require('path');\nconst exists = (workspacePath, filename) => fs.existsSync(path.join(workspacePath, filename));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Refresh the file list before offering Create.","Switch the UI to Edit mode when the file is present.","Handle the 'already exists' rejection by routing to the save flow."],"tags":["env","filesystem","state-conflict","ipc"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}