{"record":{"id":"862eb270ddca2a6c","repo":"usebruno/bruno","slug":"invalid-format-format-862eb2","errorCode":null,"errorMessage":"Invalid format: ${format}","messagePattern":"Invalid format: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/bruno-electron/src/utils/collection-import.js","lineNumber":125,"sourceCode":"\n  if (format === 'yml') {\n    brunoConfig.opencollection = '1.0.0';\n    const collectionContent = await stringifyCollection(collection.root, brunoConfig, { format });\n    await writeFile(path.join(collectionPath, 'opencollection.yml'), collectionContent);\n  } else if (format === 'bru') {\n    const bruJsonConfig = { ...brunoConfig, version: '1' };\n    if (brunoConfig.version) {\n      bruJsonConfig.collectionVersion = brunoConfig.version;\n    } else {\n      delete bruJsonConfig.collectionVersion;\n    }\n    const stringifiedBrunoConfig = await stringifyJson(bruJsonConfig);\n    await writeFile(path.join(collectionPath, 'bruno.json'), stringifiedBrunoConfig);\n\n    const collectionContent = await stringifyCollection(collection.root, brunoConfig, { format });\n    await writeFile(path.join(collectionPath, 'collection.bru'), collectionContent);\n  } else {\n    throw new Error(`Invalid format: ${format}`);\n  }\n\n  const { size, filesCount } = await getCollectionStats(collectionPath);\n  brunoConfig.size = size;\n  brunoConfig.filesCount = filesCount;\n\n  // Send collection-opened event unless caller wants to handle it themselves (e.g., during onboarding)\n  if (!options.skipOpenEvent) {\n    mainWindow.webContents.send('main:collection-opened', collectionPath, uid, brunoConfig);\n    ipcMain.emit('main:collection-opened', mainWindow, collectionPath, uid, brunoConfig);\n  }\n\n  // create folder and files based on collection\n  await parseCollectionItems(collection.items, collectionPath);\n  await parseEnvironments(collection.environments, collectionPath);\n\n  return { collectionPath, uid, brunoConfig };\n}","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/utils/collection-import.js#L107-L143","documentation":"Thrown by importCollection when the format argument is neither 'yml' nor 'bru'. The function defaults format to DEFAULT_COLLECTION_FORMAT, so this branch only fires if a caller explicitly passes an unsupported value.","triggerScenarios":"Calling importCollection(..., format) with undefined replaced by an invalid string, or a format value from an unversioned import source (e.g. a legacy 'json' format) that the writer does not support.","commonSituations":"Forwarding an unvalidated format from a file-picker/CLI/import-dialog; version skew between the importer UI and the supported formats; passing null which then bypasses the default param.","solutions":["Whitelist format to 'bru' | 'yml' at the IPC boundary and reject unknown values before importCollection.","Fall back to DEFAULT_COLLECTION_FORMAT when format is missing or unsupported rather than throwing mid-write.","Ensure the renderer/import dialog only offers the two supported formats."],"exampleFix":"// before\n} else {\n  throw new Error(`Invalid format: ${format}`);\n}\n\n// after: coerce at entry\nconst SUPPORTED = new Set(['bru', 'yml']);\nconst safeFormat = SUPPORTED.has(format) ? format : DEFAULT_COLLECTION_FORMAT;","handlingStrategy":"validation","validationCode":"const SUPPORTED_FORMATS = new Set(['bru', 'yml']);\nconst safeFormat = SUPPORTED_FORMATS.has(format) ? format : DEFAULT_COLLECTION_FORMAT;\nawait importCollection(collection, collectionLocation, mainWindow, uniqueFolderName, safeFormat, options);","typeGuard":"function isSupportedFormat(format) {\n  return format === 'bru' || format === 'yml';\n}","tryCatchPattern":"try {\n  await importCollection(collection, collectionLocation, mainWindow, uniqueFolderName, format, options);\n} catch (err) {\n  if (err.message.startsWith('Invalid format')) {\n    return importCollection(collection, collectionLocation, mainWindow, uniqueFolderName, DEFAULT_COLLECTION_FORMAT, options);\n  }\n  throw err;\n}","preventionTips":["Allow-list the format at the IPC boundary.","Default to DEFAULT_COLLECTION_FORMAT when the value is missing.","Have the import dialog only expose the two supported formats."],"tags":["import","validation","format"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}