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

  1. Use only supported content types: "application/json" or "text/html".
  2. Fix case/whitespace: the lookup is exact, so normalize the string (trim, lowercase).
  3. Guard undefined contentType before calling; the empty message suggests an undefined variable.
  4. 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

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


AI-assisted analysis of basecamp/trix@4700401311 (2026-09-02). Data as JSON: /api/errors/8c4c4be780f04a0f. Report an issue: GitHub.