{"record":{"id":"25d218d102dc4ba4","repo":"usebruno/bruno","slug":"no-files-selected","errorCode":null,"errorMessage":"No files selected","messagePattern":"No files selected","errorType":"validation","errorClass":"BrunoError","httpStatus":null,"severity":"error","filePath":"packages/bruno-app/src/utils/importers/file-reader.js","lineNumber":45,"sourceCode":"  return new Promise((resolve, reject) => {\n    const fileReader = new FileReader();\n    fileReader.onload = (e) => {\n      try {\n        const parsed = JSON.parse(e.target.result);\n        resolve({ fileName: file.name, content: parsed });\n      } catch (err) {\n        console.error(err);\n        reject(new BrunoError(`Unable to parse JSON file: ${file.name}`));\n      }\n    };\n    fileReader.onerror = (err) => reject(err);\n    fileReader.readAsText(file);\n  });\n};\n\nexport const readMultipleFiles = async (files) => {\n  if (!files || files.length === 0) {\n    throw new BrunoError('No files selected');\n  }\n\n  const parsedFiles = [];\n\n  for (const file of files) {\n    if (!file.name.toLowerCase().endsWith('.json')) {\n      throw new BrunoError(`Invalid file type: ${file.name}. Only JSON files are supported.`);\n    }\n\n    try {\n      const parsedFile = await readFile(file);\n      parsedFiles.push(parsedFile);\n    } catch (err) {\n      throw new BrunoError(`Failed to read ${file.name}: ${err.message}`);\n    }\n  }\n\n  return parsedFiles;","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/usebruno/bruno/blob/9bdd81c7bdc57006e5f5ebffb79321a8d979f712/packages/bruno-app/src/utils/importers/file-reader.js#L27-L63","documentation":"Entry guard in readMultipleFiles. Fires when the files argument is null/undefined or an empty array, before any file is read.","triggerScenarios":"readMultipleFiles(), readMultipleFiles(null), or readMultipleFiles([]). Typical when the file input change event fires with no selection or the caller forgets to pass the FileList.","commonSituations":"UI wiring bug where the import button is enabled before a file is chosen, or programmatic calls that pass an empty selection.","solutions":["Disable the import button until at least one file is selected.","Pass the actual FileList from the input element to readMultipleFiles.","Add an early return when files?.length === 0 in the calling component."],"exampleFix":"// before\nconst parsed = await readMultipleFiles(input.files);\n// after\nif (!input.files?.length) {\n  toast('Choose a file first');\n  return;\n}\nconst parsed = await readMultipleFiles(Array.from(input.files));","handlingStrategy":"validation","validationCode":"if (!files || files.length === 0) {\n  throw new Error('No files selected');\n}","typeGuard":"function hasSelectedFiles(files) {\n  return Array.isArray(files) && files.length > 0;\n}","tryCatchPattern":"try {\n  await readMultipleFiles(files);\n} catch (err) {\n  if (err.message === 'No files selected') toast('Please choose at least one file');\n  throw err;\n}","preventionTips":["Disable the import button until at least one file is chosen.","Pass the actual FileList (Array.from) to readMultipleFiles.","Add an early return in the UI when no files are selected."],"tags":["import","filesystem","validation","guard"],"backgroundTag":null,"analyzedSha":"9bdd81c7bdc57006e5f5ebffb79321a8d979f712","analyzedAt":"2026-08-13T04:09:25.751Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}