Mintplex-Labs/anything-llm · error · Error

Unsupported export type: ${type}

Error message

Unsupported export type: ${type}

What it means

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.

Source

Thrown at server/utils/chats/exportChatToFile.js:254

      return response.send(Buffer.from(md, "utf-8"));
    }
    case "plaintext": {
      const txt = chatHistoryToPlainText(convertToChatHistory(chats), meta);
      response.setHeader("Content-Type", "text/plain");
      return response.send(Buffer.from(txt, "utf-8"));
    }
    case "json": {
      const json = chatHistoryToJSON(convertToChatHistory(chats), meta);
      response.setHeader("Content-Type", "application/json");
      return response.send(Buffer.from(json, "utf-8"));
    }
    case "html": {
      const html = chatHistoryToHTML(convertToChatHistory(chats), meta);
      response.setHeader("Content-Type", "text/html");
      return response.send(Buffer.from(html, "utf-8"));
    }
    default:
      throw new Error(`Unsupported export type: ${type}`);
  }
}

module.exports = { sendChatHistoryFile, validExportTypes };

View on GitHub (pinned to 526360e320)

Solutions

  1. Use one of the rendered types: 'pdf', 'markdown', 'plaintext', 'json', 'html'.
  2. Validate `type` against the exported validExportTypes array before calling sendChatHistoryFile.
  3. Route csv/jsonl/jsonAlpaca exports through exportChatsAsType (convertTo.js), not this function.
  4. Return 400 with the allowed list when the type is unknown.

Example fix

// before
await sendChatHistoryFile(res, chats, meta, type); // type='csv' -> throws

// after
const validExportTypes = ['pdf','markdown','plaintext','json','html'];
if (!validExportTypes.includes(type))
  return res.status(400).json({ error: `type must be one of ${validExportTypes.join(',')}` });
await sendChatHistoryFile(res, chats, meta, type);
Defensive patterns

Strategy: validation

Validate before calling

const { validExportTypes } = require('../utils/chats/exportChatToFile');
if (!validExportTypes.includes(type))
  return res.status(400).json({ error: `type must be one of ${validExportTypes.join(',')}` });

Type guard

type HistoryFileType = 'pdf'|'markdown'|'plaintext'|'json'|'html';
function isHistoryFileType(v): v is HistoryFileType {
  return ['pdf','markdown','plaintext','json','html'].includes(v);
}

Try / catch

try {
  await sendChatHistoryFile(res, chats, meta, type);
} catch (e) {
  if (e.message.startsWith('Unsupported export type:')) return res.status(400).json({ error: e.message });
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/517062c8c994e078. Report an issue: GitHub.