{"record":{"id":"d3a6414368efe17d","repo":"usebruno/bruno","slug":"invalid-format-format-d3a641","errorCode":null,"errorMessage":"Invalid format: ${format}","messagePattern":"Invalid format: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/bruno-electron/src/utils/filesystem.js","lineNumber":238,"sourceCode":"    const stat = fs.statSync(filePath);\n    if (stat.isDirectory()) {\n      results = results.concat(searchForFiles(filePath, extension));\n    } else if (path.extname(file) === extension) {\n      results.push(filePath);\n    }\n  }\n  return results;\n};\n\n// Search for request files based on collection filetype by reading config\nconst searchForRequestFiles = (dir, collectionPath = null) => {\n  const format = getCollectionFormat(collectionPath || dir);\n  if (format === 'yml') {\n    return searchForFiles(dir, '.yml');\n  } else if (format === 'bru') {\n    return searchForFiles(dir, '.bru');\n  } else {\n    throw new Error(`Invalid format: ${format}`);\n  }\n};\n\nconst sanitizeName = (name) => {\n  const invalidCharacters = /[<>:\"/\\\\|?*\\x00-\\x1F]/g;\n  name = name\n    .replace(invalidCharacters, '-') // replace invalid characters with hyphens\n    .replace(/^[\\s\\-]+/, '') // remove leading spaces and hyphens\n    .replace(/[.\\s]+$/, ''); // remove trailing dots and spaces\n  return name;\n};\n\nconst isWindowsOS = () => {\n  return os.platform() === 'win32';\n};\n\n/**\n * Generate a unique name by adding a \"copy\" suffix if needed","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-electron/src/utils/filesystem.js#L220-L256","documentation":"Thrown by searchForRequestFiles in the else-branch when format is not 'yml' or 'bru'. In practice this branch is unreachable: format comes from getCollectionFormat, which only returns 'yml' or 'bru' (or throws 'No collection configuration found' itself). The throw is defensive against a future change to getCollectionFormat's return set.","triggerScenarios":"Effectively unreachable unless getCollectionFormat is modified to return a third value. Under current code, if neither opencollection.yml nor bruno.json exists, getCollectionFormat throws 'No collection configuration found' before this line is hit.","commonSituations":"Encountered only during refactors that extend getCollectionFormat with new formats without updating searchForRequestFiles; or if a caller bypasses getCollectionFormat and feeds a raw format through a different path.","solutions":["Treat as an invariant assertion; if it fires, sync the format switch in searchForRequestFiles with getCollectionFormat's return values.","Add a test asserting searchForRequestFiles covers every value getCollectionFormat can return.","If extending formats, update both functions together."],"exampleFix":"// before\n} else {\n  throw new Error(`Invalid format: ${format}`);\n}\n\n// after: exhaustive dispatch\nswitch (format) {\n  case 'yml': return searchForFiles(dir, '.yml');\n  case 'bru': return searchForFiles(dir, '.bru');\n  default: throw new Error(`searchForRequestFiles: unsupported format '${format}' from getCollectionFormat`);\n}","handlingStrategy":"validation","validationCode":"// Defensive only: getCollectionFormat never returns a third value today.\n// If you extend it, update this switch in lockstep.\nconst format = getCollectionFormat(dir);\nassert(['yml', 'bru'].includes(format), `unexpected format ${format}`);","typeGuard":"function isKnownCollectionFormat(format) {\n  return format === 'yml' || format === 'bru';\n}","tryCatchPattern":"try {\n  return searchForRequestFiles(dir, collectionPath);\n} catch (err) {\n  if (err.message.startsWith('Invalid format')) {\n    // getCollectionFormat returned something new; fall back to .bru\n    return searchForFiles(dir, '.bru');\n  }\n  throw err;\n}","preventionTips":["When extending getCollectionFormat, update searchForRequestFiles in the same commit.","Add a test mapping every getCollectionFormat return value to a search branch.","Treat the else-throw as an invariant, not an expected user error."],"tags":["filesystem","dead-code","format","defensive"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}