instructure/canvas-lms · error · FieldTooLongError
# is too long, max length is # characters
Error message
#{type} is too long, max length is #{max} characters What it means
Quizzes::QuizQuestion::RawFields#check_length raises FieldTooLongError when an HTML field (question text, answer HTML, comment, etc.) exceeds its configured maximum length. It is a guard used by fetch_with_enforced_length to prevent oversized quiz question fields from being persisted.
Solutions
- Shorten the offending HTML field (question text, answers, or comments) below the max length
- Strip or compress the HTML (remove styles/scripts, convert to plain text) before importing
- For migrations, pre-process QTI/CSV content to truncate or split oversized fields
- If legitimate content needs more space, request a limit adjustment for the field type
Example fix
// before question_text = long_html_string // after question_text = long_html_string[0, QuizQuestion::MAX_QUESTION_LENGTH]
Defensive patterns
Strategy: validation
Validate before calling
raise if question_text && question_text.length > 15_000
answer_html.each { |a| raise if a.length > max_answer_length } Type guard
def field_within_limit?(html, max) html.nil? || html.length <= max end
Try / catch
begin fields = quiz_question.fetch_with_enforced_length rescue Quizzes::QuizQuestion::RawFields::FieldTooLongError => e # truncate source content and retry, or surface a validation message end
Prevention
- Truncate HTML fields to the enforced limits at import time
- Strip styles/scripts before saving question content
- Add length checks to quiz import pipelines (QTI/CSV)
- Sanitize pasted rich-text in editors before submission
When it happens
Trigger: Fetching raw fields of a quiz question where question_text, answer_html, or comment_html exceeds the per-type max length — typically when a question was imported from QTI/external content or built via API with very long HTML.
Common situations: Migrating quiz banks from other LMSs with larger field limits; pasting large rich-text/HTML into question or answer editors; API/CSV imports without length checks; older questions that predate the limit.
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
- A maximum of 50 assessees can be provided at once
- A maximum of 50 assessors can be provided at once
- COUNT must be <=
- pseudonym cannot have a unique_id of length #
- and cannot be used together
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/fbaca8bfbbb830c6.
Report an issue: GitHub.
Appendix: source
Thrown at app/models/quizzes/quiz_question/raw_fields.rb:54
end
end
def fetch_with_enforced_length(key, opts = {})
default = opts.fetch(:default, "")
max_size = opts.fetch(:max_size, 16.kilobytes)
check_length(fetch_any(key, default), key_to_type(key), max_size)
end
def sanitize(html)
Sanitize.clean(html || "", CanvasSanitize::SANITIZE)
end
private
def check_length(html, type, max)
if html && html.length > max
raise FieldTooLongError, "#{type} is too long, max length is #{max} characters"
end
html
end
def key_to_type(key)
key.to_s.humanize.downcase
end
end
View on GitHub (pinned to 1c9f0bb801)