{"record":{"id":"bcf55a7f15195a6b","repo":"Kong/insomnia","slug":"failed-to-read-directory-err","errorCode":null,"errorMessage":"Failed to read directory: ${err}","messagePattern":"Failed to read directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/insomnia/src/main/ipc/main.ts","lineNumber":145,"sourceCode":"\n  return sanitizedConfig;\n};\n\nconst readDir = async (_: unknown, options: { path: string }) => {\n  try {\n    const files = await fs.promises.readdir(options.path);\n    return files\n      .map(file => {\n        const filePath = path.join(options.path, file);\n        return {\n          type: fs.statSync(filePath).isDirectory() ? 'directory' : fs.statSync(filePath).isFile() ? 'file' : 'other',\n          name: file,\n          path: filePath,\n        };\n      })\n      .filter(file => file.type !== 'other');\n  } catch (err) {\n    throw new Error(`Failed to read directory: ${err}`);\n  }\n};\n\nconst writeResponseBodyToFile = async (\n  _: unknown,\n  options: { sourcePath: string; destinationPath: string; bodyCompression?: 'zip' | null },\n) => {\n  // Validate sourcePath is within the expected responses directory to prevent a\n  // compromised renderer from using this handler to read arbitrary files on disk.\n  const userdataDirectory = process.env.INSOMNIA_DATA_PATH || app.getPath('userData');\n  const allowedResponsesDir = path.join(userdataDirectory, 'responses');\n  const resolvedSource = path.resolve(options.sourcePath);\n  if (!resolvedSource.startsWith(allowedResponsesDir + path.sep) || !resolvedSource.endsWith('.response')) {\n    throw new Error(\n      'writeResponseBodyToFile: sourcePath is outside the allowed responses directory or does not end in .response',\n    );\n  }\n","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/Kong/insomnia/blob/d9bb2b0142600f21309832daea3317942d285984/packages/insomnia/src/main/ipc/main.ts#L127-L163","documentation":"Error \"Failed to read directory: ${err}\" thrown in Kong/insomnia.","triggerScenarios":"Thrown at packages/insomnia/src/main/ipc/main.ts:145 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d9bb2b0142600f21309832daea3317942d285984","analyzedAt":"2026-08-26T18:04:05.187Z","schemaVersion":2},"datasetVersion":"2026-08-26T21:11:00.512Z"}