{"record":{"id":"4098086066daafd7","repo":"basecamp/trix","slug":"unknown-content-type-contenttype","errorCode":null,"errorMessage":"unknown content type: ${contentType}","messagePattern":"unknown content type: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/trix/core/serialization.js","lineNumber":91,"sourceCode":"  },\n}\n\nconst deserializers = {\n  \"application/json\": function(string) {\n    return Document.fromJSONString(string)\n  },\n\n  \"text/html\": function(string) {\n    return HTMLParser.parse(string).getDocument()\n  },\n}\n\nexport const serializeToContentType = function(serializable, contentType) {\n  const serializer = serializers[contentType]\n  if (serializer) {\n    return serializer(serializable)\n  } else {\n    throw new Error(`unknown content type: ${contentType}`)\n  }\n}\n\nexport const deserializeFromContentType = function(string, contentType) {\n  const deserializer = deserializers[contentType]\n  if (deserializer) {\n    return deserializer(string)\n  } else {\n    throw new Error(`unknown content type: ${contentType}`)\n  }\n}\n","sourceCodeStart":73,"sourceCodeEnd":103,"githubUrl":"https://github.com/basecamp/trix/blob/470040131122bd44e269b4de0f2e9557f90ec994/src/trix/core/serialization.js#L73-L103","documentation":"ES-module version of the same guard in src/trix/core/serialization.js: serializeToContentType throws when the contentType key is absent from the serializers map. Trix supports only \"application/json\" and \"text/html\" for serialization.","triggerScenarios":"importing serializeToContentType from trix core and calling it with any contentType other than \"application/json\"/\"text/html\", including undefined/null or custom types like \"text/plain\".","commonSituations":"Building custom attachment serialization with a MIME type; refactors that renamed content-type constants; server-driven content types passed straight through.","solutions":["Restrict calls to \"application/json\" or \"text/html\".","Add a whitelist check or default branch before calling serializeToContentType.","Log/inspect the actual contentType value — undefined produces the bare \"unknown content type: undefined\" message.","Preprocess unsupported types (e.g. HTML-parse) into a supported format."],"exampleFix":"// before\nexport const serialize = (data, type) => serializeToContentType(data, type)\n// after\nconst SUPPORTED = [\"application/json\", \"text/html\"]\nexport const serialize = (data, type) => {\n  if (!SUPPORTED.includes(type)) type = \"text/html\"\n  return serializeToContentType(data, type)\n}","handlingStrategy":"validation","validationCode":"const SUPPORTED = [\"application/json\", \"text/html\"]\nif (!SUPPORTED.includes(contentType)) {\n  contentType = \"text/html\"\n}","typeGuard":"const isSupported = (ct) => typeof ct === \"string\" && [\"application/json\", \"text/html\"].includes(ct)","tryCatchPattern":"try {\n  return serializeToContentType(data, contentType)\n} catch (e) {\n  if (/^unknown content type/.test(e.message)) {\n    return serializeToContentType(data, \"text/html\")\n  }\n  throw e\n}","preventionTips":["Centralize content-type constants in one module shared by callers.","Never pass MIME types read from attachments directly into serializeToContentType.","Log the offending contentType in a wrapper for diagnosis."],"tags":["serialization","invalid-argument","esm","trix"],"backgroundTag":"unknown-content-type","analyzedSha":"470040131122bd44e269b4de0f2e9557f90ec994","analyzedAt":"2026-09-02T10:19:15.878Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}