basecamp/trix · error · Error
unknown content type:
Error message
unknown content type:
What it means
serializeToContentType looks up the contentType in a fixed serializers map ("application/json", "text/html"). Any other or empty content type has no serializer and throws. It indicates an unsupported or misspelled content type string was supplied.
Source
Thrown at action_text-trix/app/assets/javascripts/trix.js:9977
} catch (error) {}
});
return element.innerHTML.replace(blockCommentPattern, "");
}
};
const deserializers = {
"application/json": function (string) {
return Document.fromJSONString(string);
},
"text/html": function (string) {
return HTMLParser.parse(string).getDocument();
}
};
const serializeToContentType = function (serializable, contentType) {
const serializer = serializers[contentType];
if (serializer) {
return serializer(serializable);
} else {
throw new Error("unknown content type: ".concat(contentType));
}
};
const deserializeFromContentType = function (string, contentType) {
const deserializer = deserializers[contentType];
if (deserializer) {
return deserializer(string);
} else {
throw new Error("unknown content type: ".concat(contentType));
}
};
var core = /*#__PURE__*/Object.freeze({
__proto__: null
});
class ManagedAttachment extends BasicObject {
constructor(attachmentManager, attachment) {
super(...arguments);View on GitHub (pinned to 4700401311)
Solutions
- Use only supported content types: "application/json" or "text/html".
- Fix case/whitespace: the lookup is exact, so normalize the string (trim, lowercase).
- Guard undefined contentType before calling; the empty message suggests an undefined variable.
- If you need another format, convert manually via one of the supported serializers.
Example fix
// before serializeToContentType(data, attachment.getType()) // may be "image/png" // after const ct = attachment.getType() === "application/json" ? "application/json" : "text/html" serializeToContentType(data, ct)
Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED = ["application/json", "text/html"]
if (!SUPPORTED.includes(contentType)) {
throw new Error(`Unsupported content type: ${contentType}; use one of ${SUPPORTED.join(", ")}`)
} Type guard
const isSupportedContentType = (ct) => ct === "application/json" || ct === "text/html"
Try / catch
try {
return serializeToContentType(data, contentType)
} catch (e) {
if (e.message.startsWith("unknown content type")) {
console.warn(`Falling back to text/html; received contentType=${JSON.stringify(contentType)}`)
return serializeToContentType(data, "text/html")
}
throw e
} Prevention
- Keep content types as named constants, not raw strings from external data.
- Normalize (trim/lowercase) MIME values from attachments or headers before use.
- Default to a known type when the source type is unknown.
When it happens
Trigger: Calling serializeToContentType(data, "text/plain"), serializeToContentType(data, ""), or with an undefined/mistyped content-type variable.
Common situations: Reading a MIME type from an attachment or HTTP header that Trix doesn't support; typos like "application/JSON"; passing a variable that is undefined at runtime so the message renders as "unknown content type: ".
Related errors
- unknown content type: ${contentType}
- unserializable object
- unserializable object
- This browser does not support the .form property for trix-ed
- This browser does not support the .name property for trix-ed
AI-assisted analysis of basecamp/trix@4700401311 (2026-09-02).
Data as JSON: /api/errors/8c4c4be780f04a0f.
Report an issue: GitHub.