{"record":{"id":"1cae54071e88826b","repo":"instructure/canvas-lms","slug":"texttoolongerror","errorCode":null,"errorMessage":"TextTooLongError","messagePattern":"TextTooLongError","errorType":"exception","errorClass":"Translation::TextTooLongError","httpStatus":null,"severity":"warning","filePath":"lib/translation.rb","lineNumber":139,"sourceCode":"      if source == target\n        InstStatsd::Statsd.distributed_increment(\"translation.errors\", tags: [\"error:same_language\"])\n        raise Translation::SameLanguageTranslationError\n      end\n    end\n\n    def collect_translation_stats(src_lang:, tgt_lang:, type:)\n      tags = %W[type:#{type} source_language:#{src_lang} dest_language:#{tgt_lang}]\n      InstStatsd::Statsd.distributed_increment(\"translation.invocations\", tags:)\n    end\n\n    def handle_cedar_errors\n      yield\n    rescue => e\n      case e.class.name\n      when /SameLanguageTranslationError/\n        raise SameLanguageTranslationError\n      when /ContentTooLongError/\n        raise TextTooLongError\n      when /UnsupportedLanguageError/\n        raise UnsupportedLanguageError\n      when /ValidationError/\n        raise ValidationError\n      else\n        raise TranslationError, e.message\n      end\n    end\n  end\nend\n","sourceCodeStart":121,"sourceCodeEnd":150,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/translation.rb#L121-L150","documentation":"Translation#handle_cedar_errors maps Cedar client ContentTooLongError-class exceptions to Canvas's Translation::TextTooLongError. It is raised when the submitted text/HTML exceeds the translation service's maximum content length, so the request is rejected before any translation is produced.","triggerScenarios":"translate_text/translate_html called with content whose length exceeds the Cedar service limit, and CedarClient raising an exception whose class name matches /ContentTooLongError/ — e.g. translating an entire long discussion post or a large HTML document in one call.","commonSituations":"Translating long discussion entries, submission comments, or whole-page HTML; limits lowered on the translation service; concatenated user content exceeding caps; callers chunking incorrectly or not at all.","solutions":["Truncate or chunk long content below the service's length limit before translating","Rescue Translation::TextTooLongError and show a 'content too long to translate' message","Translate per-message/per-section instead of aggregating large bodies","Pre-check content length against the documented Cedar limit before calling"],"exampleFix":"# before\nTranslation.translate_text(text: long_body, tgt_lang: 'es', options: opts)\n# after\nif long_body.length > MAX_TRANSLATION_LENGTH\n  chunks = long_body.scan(/.{1,#{MAX_TRANSLATION_LENGTH}}/m)\n  translated = chunks.map { |c| Translation.translate_text(text: c, tgt_lang: 'es', options: opts) }.join\nelse\n  translated = Translation.translate_text(text: long_body, tgt_lang: 'es', options: opts)\nend","handlingStrategy":"try-catch","validationCode":"# pre-check content length against the service limit\nraise Translation::TextTooLongError if content.length > MAX_TRANSLATION_LENGTH","typeGuard":null,"tryCatchPattern":"begin\n  Translation.translate_text(text: content, tgt_lang: tgt, options: opts)\nrescue Translation::TextTooLongError\n  Rails.logger.info(\"Content too long to translate (#{content.length} chars)\")\n  nil\nend","preventionTips":["Chunk long documents before translating","Translate per message/section rather than concatenated blobs","Track the service's max content length in a constant","Handle TextTooLongError gracefully in UI with user feedback"],"tags":["translation","i18n","payload-too-large","cedar"],"backgroundTag":"payload-too-large","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}