instructure/canvas-lms · warning · Translation::TextTooLongError
TextTooLongError
Error message
TextTooLongError
What it means
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.
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
Example fix
# before
Translation.translate_text(text: long_body, tgt_lang: 'es', options: opts)
# after
if long_body.length > MAX_TRANSLATION_LENGTH
chunks = long_body.scan(/.{1,#{MAX_TRANSLATION_LENGTH}}/m)
translated = chunks.map { |c| Translation.translate_text(text: c, tgt_lang: 'es', options: opts) }.join
else
translated = Translation.translate_text(text: long_body, tgt_lang: 'es', options: opts)
end Defensive patterns
Strategy: try-catch
Validate before calling
# pre-check content length against the service limit raise Translation::TextTooLongError if content.length > MAX_TRANSLATION_LENGTH
Try / catch
begin
Translation.translate_text(text: content, tgt_lang: tgt, options: opts)
rescue Translation::TextTooLongError
Rails.logger.info("Content too long to translate (#{content.length} chars)")
nil
end Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- Translation::SameLanguageTranslationError
- SameLanguageTranslationError
- UnsupportedLanguageError
- Cedar rate limit exceeded for #
- e.message
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/1cae54071e88826b.
Report an issue: GitHub.
Appendix: source
Thrown at lib/translation.rb:139
if source == target
InstStatsd::Statsd.distributed_increment("translation.errors", tags: ["error:same_language"])
raise Translation::SameLanguageTranslationError
end
end
def collect_translation_stats(src_lang:, tgt_lang:, type:)
tags = %W[type:#{type} source_language:#{src_lang} dest_language:#{tgt_lang}]
InstStatsd::Statsd.distributed_increment("translation.invocations", tags:)
end
def handle_cedar_errors
yield
rescue => e
case e.class.name
when /SameLanguageTranslationError/
raise SameLanguageTranslationError
when /ContentTooLongError/
raise TextTooLongError
when /UnsupportedLanguageError/
raise UnsupportedLanguageError
when /ValidationError/
raise ValidationError
else
raise TranslationError, e.message
end
end
end
end
View on GitHub (pinned to 1c9f0bb801)