{"record":{"id":"a578f4d7cf4c4b19","repo":"Mintplex-Labs/anything-llm","slug":"invalid-export-type-format","errorCode":null,"errorMessage":"Invalid export type: ${format}","messagePattern":"Invalid export type: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/helpers/chat/convertTo.js","lineNumber":47,"sourceCode":"async function convertToJSON(preparedData) {\n  return JSON.stringify(preparedData, null, 4);\n}\n\n// ref: https://raw.githubusercontent.com/gururise/AlpacaDataCleaned/main/alpaca_data.json\nasync function convertToJSONAlpaca(preparedData) {\n  return JSON.stringify(preparedData, null, 4);\n}\n\n// You can validate JSONL outputs on https://jsonlines.org/validator/\nasync function convertToJSONL(workspaceChatsMap) {\n  return Object.values(workspaceChatsMap)\n    .map((workspaceChats) => JSON.stringify(workspaceChats))\n    .join(\"\\n\");\n}\n\nasync function prepareChatsForExport(format = \"jsonl\", chatType = \"workspace\") {\n  if (!exportMap.hasOwnProperty(format))\n    throw new Error(`Invalid export type: ${format}`);\n\n  let chats;\n  if (chatType === \"workspace\") {\n    chats = await WorkspaceChats.whereWithData({}, null, null, {\n      id: \"asc\",\n    });\n  } else if (chatType === \"embed\") {\n    chats = await EmbedChats.whereWithEmbedAndWorkspace(\n      {},\n      null,\n      {\n        id: \"asc\",\n      },\n      null\n    );\n  } else {\n    throw new Error(`Invalid chat type: ${chatType}`);\n  }","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/helpers/chat/convertTo.js#L29-L65","documentation":"Thrown by prepareChatsForExport() when the requested format is not a key in exportMap. The map supports exactly four formats: json, csv, jsonl, jsonAlpaca. Any other format string (including typos or the chat-history-file types like 'pdf') is rejected here because there is no converter function for it. This is the format-validation gate before any DB query runs.","triggerScenarios":"Calling prepareChatsForExport('pdf'), 'xlsx', 'JSON' (case matters), '' or undefined-format exports. A frontend export button passing a format the data layer does not recognize.","commonSituations":"Confusing the data-export formats (convertTo.js: json/csv/jsonl/jsonAlpaca) with the chat-history-file formats (exportChatToFile.js: pdf/markdown/plaintext/json/html); a typo in a config; an older client after formats were renamed.","solutions":["Use one of the supported formats: 'json', 'csv', 'jsonl', 'jsonAlpaca'.","At the call site, validate against exportMap keys or the exported validExportTypes array before invoking.","For document-style exports (pdf/markdown/html), use sendChatHistoryFile, not prepareChatsForExport.","Lowercase and trim the format input, then re-check, to absorb minor client variation."],"exampleFix":"// before\nconst out = await prepareChatsForExport(format); // format='PDF' -> throws\n\n// after\nconst validExportTypes = ['json','csv','jsonl','jsonAlpaca'];\nconst fmt = validExportTypes.includes(format) ? format : 'jsonl';\nconst out = await prepareChatsForExport(fmt);","handlingStrategy":"validation","validationCode":"const validExportTypes = ['json','csv','jsonl','jsonAlpaca'];\nif (!validExportTypes.includes(format))\n  return res.status(400).json({ error: `format must be one of ${validExportTypes.join(',')}` });","typeGuard":"type ExportFormat = 'json'|'csv'|'jsonl'|'jsonAlpaca';\nfunction isExportFormat(v): v is ExportFormat {\n  return ['json','csv','jsonl','jsonAlpaca'].includes(v);\n}","tryCatchPattern":"try {\n  await prepareChatsForExport(format, chatType);\n} catch (e) {\n  if (e.message.startsWith('Invalid export type:')) return res.status(400).json({ error: e.message });\n  throw e;\n}","preventionTips":["Import and reuse the exported validExportTypes constant instead of hardcoding.","Do not confuse data-export formats with chat-history-file types.","Lowercase and trim client input before validating."],"tags":["validation","export","chat-history"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}