hcengineering/platform · error · Error
Unknown content format
Error message
Unknown content format
What it means
fetchMarkup converts stored collaborative markup into a requested format ('markup', 'html', or 'markdown'). If the format argument matches none of these cases, the switch falls through to default and throws 'Unknown content format'. This indicates an invalid or unsupported MarkupFormat value at runtime.
Source
Thrown at foundations/core/packages/api-client/src/markup/client.ts:76
objectClass: Ref<Class<Doc>>,
objectId: Ref<Doc>,
objectAttr: string,
doc: MarkupRef,
format: MarkupFormat
): Promise<string> {
const collabId = makeCollabId(objectClass, objectId, objectAttr)
const markup = await this.collaborator.getMarkup(collabId, doc)
const json = markupToJSON(markup)
switch (format) {
case 'markup':
return markup
case 'html':
return jsonToHTML(json)
case 'markdown':
return markupToMarkdown(json, { refUrl: this.refUrl, imageUrl: this.imageUrl })
default:
throw new Error('Unknown content format')
}
}
async uploadMarkup (
objectClass: Ref<Class<Doc>>,
objectId: Ref<Doc>,
objectAttr: string,
value: string,
format: MarkupFormat
): Promise<MarkupRef> {
let markup: Markup = ''
switch (format) {
case 'markup':
markup = value
break
case 'html':
markup = jsonToMarkup(htmlToJSON(value))View on GitHub (pinned to 63e28dc964)
Solutions
- Pass exactly one of 'markup', 'html', or 'markdown' as the format argument.
- Validate/normalize the format string (lowercase, map aliases like 'md' -> 'markdown') before calling fetchMarkup.
- Use the MarkupFormat type and avoid unchecked casts so TypeScript rejects invalid values.
Example fix
// before
client.fetchMarkup(cls, id, 'content', doc, 'md' as MarkupFormat)
// after
const fmt = format === 'md' ? 'markdown' : format
if (!['markup', 'html', 'markdown'].includes(fmt)) throw new Error('unsupported format: ' + format)
client.fetchMarkup(cls, id, 'content', doc, fmt as MarkupFormat) Defensive patterns
Strategy: validation
Validate before calling
const FORMATS = ['markup', 'html', 'markdown'] as const
if (!FORMATS.includes(format as any)) throw new Error(`Invalid markup format: ${format}; expected one of ${FORMATS.join(', ')}`) Type guard
function isMarkupFormat(v: unknown): v is 'markup' | 'html' | 'markdown' {
return v === 'markup' || v === 'html' || v === 'markdown'
} Try / catch
try {
return await client.fetchMarkup(cls, id, attr, doc, format)
} catch (e) {
if (e instanceof Error && e.message === 'Unknown content format') {
throw new Error(`Unsupported export format "${String(format)}" — use 'markup', 'html' or 'markdown'`)
}
throw e
} Prevention
- Always type format parameters as MarkupFormat and avoid `as` casts from raw strings
- Normalize external input (toLowerCase, alias map like md->markdown) before calling
- Unit-test each supported format string your UI can produce
When it happens
Trigger: Calling fetchMarkup(objectClass, objectId, attr, doc, format) with format that is not exactly 'markup' | 'html' | 'markdown' — e.g. 'md', 'text', 'richtext', or a value cast incorrectly to MarkupFormat.
Common situations: Hand-building a format string instead of using the MarkupFormat type, user-configurable export format from a UI/config reaching the API unvalidated, TypeScript types bypassed with `as MarkupFormat`.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Message id is required
- Failed to load server config
- getDisplayMedia not supported
- No screen access granted
- Message id is required
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/e9fb2a3f056f9cf2.
Report an issue: GitHub.