{"record":{"id":"243c7b0c15c5f376","repo":"Mintplex-Labs/anything-llm","slug":"invalid-chat-type-chattype","errorCode":null,"errorMessage":"Invalid chat type: ${chatType}","messagePattern":"Invalid chat type: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/helpers/chat/convertTo.js","lineNumber":64,"sourceCode":"  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  }\n\n  if (format === \"csv\" || format === \"json\") {\n    const preparedData = chats.map((chat) => {\n      const responseJson = safeJsonParse(chat.response, {});\n      const baseData = {\n        id: chat.id,\n        prompt: chat.prompt,\n        response: responseJson.text,\n        sent_at: chat.createdAt,\n        // Only add attachments to the json format since we cannot arrange attachments in csv format\n        ...(format === \"json\"\n          ? {\n              attachments:\n                responseJson.attachments?.length > 0\n                  ? responseJson.attachments.map((attachment) => ({\n                      type: \"image\",\n                      image: attachmentToDataUrl(attachment),","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/helpers/chat/convertTo.js#L46-L82","documentation":"Thrown by prepareChatsForExport() when chatType is neither 'workspace' nor 'embed'. The export pipeline queries two distinct tables (workspace_chats vs embed_chats) with different joins, so an unknown chat type has no data source. This guard runs after the format check and selects which model + query to use.","triggerScenarios":"Calling prepareChatsForExport(format, 'workspaces'), 'api', '', or any value other than the two supported ones. A client that sends chatType as a query string with a typo.","commonSituations":"An API consumer guessing the chatType enum; a frontend dropdown that previously offered a third, since-removed type; an integration hardcoded to an outdated value.","solutions":["Pass exactly 'workspace' or 'embed' as chatType.","Validate the value against a constant array at the controller and default to 'workspace' if absent.","Return 400 with the list of allowed chat types when the value is invalid.","Document the two supported chat types in your API client."],"exampleFix":"// before\nawait prepareChatsForExport('csv', chatType); // chatType='api' -> throws\n\n// after\nconst VALID = ['workspace','embed'];\nconst type = VALID.includes(chatType) ? chatType : 'workspace';\nawait prepareChatsForExport('csv', type);","handlingStrategy":"validation","validationCode":"const VALID = ['workspace','embed'];\nif (!VALID.includes(chatType))\n  return res.status(400).json({ error: `chatType must be one of ${VALID.join(',')}` });","typeGuard":"type ChatType = 'workspace'|'embed';\nfunction isChatType(v): v is ChatType { return v === 'workspace' || v === 'embed'; }","tryCatchPattern":"try {\n  await prepareChatsForExport(format, chatType);\n} catch (e) {\n  if (e.message.startsWith('Invalid chat type:')) return res.status(400).json({ error: e.message });\n  throw e;\n}","preventionTips":["Default chatType to 'workspace' when the caller omits it.","Document the two supported values in API clients.","Validate enum values at the controller boundary."],"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"}