instructure/canvas-lms · error · Translation::ValidationError
ValidationError
Error message
ValidationError
What it means
Raised by handle_cedar_errors in lib/translation.rb:143 when the Cedar translation service returns a ValidationError. The wrapper remaps it to Canvas's ValidationError, signaling the request payload (text, language params, etc.) failed upstream validation.
Solutions
- Validate input text is non-blank and within size limits before calling the translation service
- Log e.message from the wrapped error to identify which field failed upstream validation
- Rescue ValidationError and return a user-friendly message instead of surfacing the raw error
- Check for recent Cedar/API contract changes if previously valid payloads now fail
Example fix
// before Translation::Service.translate_html(body, from: nil, to: 'es') // after next if body.blank? Translation::Service.translate_html(body, from: source_locale, to: 'es')
Defensive patterns
Strategy: validation
Validate before calling
raise ValidationError if text.blank? || text.length > MAX_TRANSLATABLE_LENGTH
Try / catch
begin
translate_html(html, from:, to:)
rescue ValidationError => e
logger.warn("translation payload rejected: #{e.message}")
render json: {error: 'untranslatable content'}, status: :bad_request
end Prevention
- Check for blank content before translating
- Enforce size limits client-side
- Keep payload options aligned with the current API contract
When it happens
Trigger: translate_text or translate_html called with a payload Cedar rejects: empty/nil text, text exceeding field constraints, invalid options hash, or malformed arguments passed through to the service.
Common situations: Translating empty user-generated content without checking for blank input; passing nil source language; API contract change in Cedar adding new validation rules; oversized request fields.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- An institutional tag category did not pass validation
- app '# ' must be one of: #
- cannot change column: captions - locked by Master Course
- Cannot validate existence for resource type: #
- Caption cannot be empty.
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/0a635c487c452a89.
Report an issue: GitHub.
Appendix: source
Thrown at lib/translation.rb:143
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)