{"record":{"id":"517062c8c994e078","repo":"Mintplex-Labs/anything-llm","slug":"unsupported-export-type-type","errorCode":null,"errorMessage":"Unsupported export type: ${type}","messagePattern":"Unsupported export type: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/chats/exportChatToFile.js","lineNumber":254,"sourceCode":"      return response.send(Buffer.from(md, \"utf-8\"));\n    }\n    case \"plaintext\": {\n      const txt = chatHistoryToPlainText(convertToChatHistory(chats), meta);\n      response.setHeader(\"Content-Type\", \"text/plain\");\n      return response.send(Buffer.from(txt, \"utf-8\"));\n    }\n    case \"json\": {\n      const json = chatHistoryToJSON(convertToChatHistory(chats), meta);\n      response.setHeader(\"Content-Type\", \"application/json\");\n      return response.send(Buffer.from(json, \"utf-8\"));\n    }\n    case \"html\": {\n      const html = chatHistoryToHTML(convertToChatHistory(chats), meta);\n      response.setHeader(\"Content-Type\", \"text/html\");\n      return response.send(Buffer.from(html, \"utf-8\"));\n    }\n    default:\n      throw new Error(`Unsupported export type: ${type}`);\n  }\n}\n\nmodule.exports = { sendChatHistoryFile, validExportTypes };\n","sourceCodeStart":236,"sourceCodeEnd":259,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/chats/exportChatToFile.js#L236-L259","documentation":"Thrown by sendChatHistoryFile() in its switch default when `type` is not one of pdf, markdown, plaintext, json, html. This is the file-rendering pipeline (distinct from the data export in convertTo.js): it produces a downloadable rendered artifact. An unknown type has no renderer, so the request is rejected. The valid values are exported as validExportTypes.","triggerScenarios":"A download route like /chat-history/:type where :type is 'docx', 'csv', 'jsonl', or 'JSON'. Note 'csv'/'jsonl' belong to the data-export pipeline, not this renderer, so passing them here throws.","commonSituations":"Mixing up the two export systems; an old bookmarked URL with a now-unsupported type; a frontend bug sending the data-export format to the file-render endpoint.","solutions":["Use one of the rendered types: 'pdf', 'markdown', 'plaintext', 'json', 'html'.","Validate `type` against the exported validExportTypes array before calling sendChatHistoryFile.","Route csv/jsonl/jsonAlpaca exports through exportChatsAsType (convertTo.js), not this function.","Return 400 with the allowed list when the type is unknown."],"exampleFix":"// before\nawait sendChatHistoryFile(res, chats, meta, type); // type='csv' -> throws\n\n// after\nconst validExportTypes = ['pdf','markdown','plaintext','json','html'];\nif (!validExportTypes.includes(type))\n  return res.status(400).json({ error: `type must be one of ${validExportTypes.join(',')}` });\nawait sendChatHistoryFile(res, chats, meta, type);","handlingStrategy":"validation","validationCode":"const { validExportTypes } = require('../utils/chats/exportChatToFile');\nif (!validExportTypes.includes(type))\n  return res.status(400).json({ error: `type must be one of ${validExportTypes.join(',')}` });","typeGuard":"type HistoryFileType = 'pdf'|'markdown'|'plaintext'|'json'|'html';\nfunction isHistoryFileType(v): v is HistoryFileType {\n  return ['pdf','markdown','plaintext','json','html'].includes(v);\n}","tryCatchPattern":"try {\n  await sendChatHistoryFile(res, chats, meta, type);\n} catch (e) {\n  if (e.message.startsWith('Unsupported export type:')) return res.status(400).json({ error: e.message });\n  throw e;\n}","preventionTips":["Reuse the exported validExportTypes list rather than hardcoding.","Route csv/jsonl/jsonAlpaca through exportChatsAsType, not sendChatHistoryFile.","Validate the route param against the constant before calling."],"tags":["validation","export","chat-history","rendering"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}