{"record":{"id":"698db451ac2e8955","repo":"usebruno/bruno","slug":"invalid-collection-format-format","errorCode":null,"errorMessage":"Invalid collection format: ${format}","messagePattern":"Invalid collection format: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-electron/src/ipc/collection.js","lineNumber":1790,"sourceCode":"      const brunoConfigPath = path.join(collectionPath, 'bruno.json');\n      const content = await stringifyJson(transformedBrunoConfig);\n      await writeFile(brunoConfigPath, content);\n    } else if (format === 'yml') {\n      // opencollection.yml holds both config AND the collection root. If the caller\n      // didn't supply a root (e.g. a config-only update before the tree finished\n      // loading), recover it from disk so request defaults/docs/scripts aren't wiped.\n      let rootToWrite = collectionRoot;\n      if (!rootToWrite) {\n        const ocYmlPath = path.join(collectionPath, 'opencollection.yml');\n        if (fs.existsSync(ocYmlPath)) {\n          const existing = fs.readFileSync(ocYmlPath, 'utf8');\n          rootToWrite = parseCollection(existing, { format }).collectionRoot;\n        }\n      }\n      const content = await stringifyCollection(rootToWrite, transformedBrunoConfig, { format });\n      await writeFile(path.join(collectionPath, 'opencollection.yml'), content);\n    } else {\n      throw new Error(`Invalid collection format: ${format}`);\n    }\n  };\n\n  ipcMain.handle('renderer:update-bruno-config', async (event, brunoConfig, collectionPath, collectionRoot) => {\n    try {\n      await writeBrunoConfig(brunoConfig, collectionPath, collectionRoot);\n    } catch (error) {\n      return Promise.reject(error);\n    }\n  });\n\n  ipcMain.handle('renderer:ignore-folder', async (event, collectionUid, collectionPath, collectionRoot, brunoConfig, folderPath) => {\n    try {\n      const relativePath = path.relative(collectionPath, folderPath).replace(/\\\\/g, '/');\n      const existingIgnores = brunoConfig?.ignore || [];\n      const updatedBrunoConfig = {\n        ...brunoConfig,\n        ignore: [...new Set([...existingIgnores, relativePath])]","sourceCodeStart":1772,"sourceCodeEnd":1808,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/ipc/collection.js#L1772-L1808","documentation":"Thrown defensively by writeBrunoConfig when getCollectionFormat returns a value that is neither 'bru' nor 'yml'. Because getCollectionFormat itself only ever returns 'yml' (opencollection.yml present), 'bru' (bruno.json present), or throws its own 'No collection configuration found' error, this branch is an invariant guard: it fires only if the format detection contract has been broken (e.g. a new format was added to getCollectionFormat without a matching write branch) or if collectionPath was mutated between detection and write.","triggerScenarios":"Invoking IPC renderer:update-bruno-config (or any internal caller of writeBrunoConfig) on a collection whose detected format is a value other than 'bru' or 'yml'. In practice unreachable unless getCollectionFormat is extended without updating this switch, or the format string is externally overridden.","commonSituations":"A maintainer adds a third collection format to getCollectionFormat (filesystem.js:277) but forgets a branch in writeBrunoConfig; mid-refactor state where one of bruno.json/opencollection.yml is removed between the getCollectionFormat call and the if/else.","solutions":["If you are a user: confirm the collection directory contains either bruno.json or opencollection.yml; if neither, re-save the collection from the UI.","If you are extending formats: add an `else if (format === '<new>')` branch to writeBrunoConfig mirroring the existing yml/bru write logic.","Audit getCollectionFormat (utils/filesystem.js:277) and writeBrunoConfig together so the two stay in sync; add a unit test covering the new format."],"exampleFix":"// before\n  } else {\n    throw new Error(`Invalid collection format: ${format}`);\n  }\n\n// after\n  } else if (format === 'json') {\n    const content = await stringifyJson(transformedBrunoConfig);\n    await writeFile(path.join(collectionPath, 'collection.json'), content);\n  } else {\n    throw new Error(`Invalid collection format: ${format}`);\n  }","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst path = require('path');\nfunction detectFormat(collectionPath) {\n  if (fs.existsSync(path.join(collectionPath, 'opencollection.yml'))) return 'yml';\n  if (fs.existsSync(path.join(collectionPath, 'bruno.json'))) return 'bru';\n  return null;\n}\n// before invoking renderer:update-bruno-config\nconst fmt = detectFormat(collectionPath);\nif (fmt !== 'bru' && fmt !== 'yml') {\n  throw new Error(`Refusing to update: unsupported or missing format for ${collectionPath}`);\n}","typeGuard":"/** @param {string} f @returns {f is 'bru' | 'yml'} */\nfunction isSupportedFormat(f) {\n  return f === 'bru' || f === 'yml';\n}","tryCatchPattern":null,"preventionTips":["Keep getCollectionFormat (utils/filesystem.js:277) and writeBrunoConfig branch lists in sync; add a unit test per format.","Only call renderer:update-bruno-config on collections that contain bruno.json or opencollection.yml.","Treat 'Invalid collection format' as a programmer error, not a user-facing one — file a bug when it fires."],"tags":["ipc","collection-format","bruno-config","defensive-guard","invariant"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}