instructure/canvas-lms · error · UnsupportedContentType
Unsupported content type
Error message
Unsupported content type
What it means
StudyAssist::UnsupportedContentType is raised by resolve_file when supported_attachment?(attachment) is false. Only certain file types (e.g. text/PDF-like attachments) have text extraction support; images, media, spreadsheets, or unknown MIME types are rejected.
Solutions
- Only pass attachments of supported types (check supported_attachment? / the whitelist in study_assist.rb)
- Convert or transcribe unsupported files (e.g. OCR images) before calling
- Extend supported_attachment? to cover additional types if extraction is feasible
- Filter file pickers client-side to supported MIME types
Example fix
// before
StudyAssist.new(course:, user:, prompt:, file_id: image_attachment.id).call
// after
unless StudyAssist.supported_attachment?(image_attachment)
return render json: { error: 'unsupported file type' }, status: :unprocessable_entity
end
StudyAssist.new(course:, user:, prompt:, file_id: image_attachment.id).call Defensive patterns
Strategy: validation
Validate before calling
raise StudyAssist::UnsupportedContentType unless course.attachments.find_by(id: file_id)&.then { |a| StudyAssist.respond_to?(:supported_attachment?) ? StudyAssist.send(:supported_attachment?, a) : SUPPORTED_TYPES.include?(a.content_type) } Type guard
null
Try / catch
begin
StudyAssist.new(course:, user:, prompt:, file_id:).call
rescue StudyAssist::UnsupportedContentType
render json: { error: 'unsupported file type' }, status: :unprocessable_entity
end Prevention
- Whitelist supported MIME types in file pickers
- Check supported_attachment? logic before enabling files
- Validate content_type during upload pipelines
When it happens
Trigger: Calling #call with file_id pointing to an attachment whose content type or extension is not in the supported set (e.g. .png, .mp4, .zip, .xlsx).
Common situations: User selects an image or media file in the UI while expecting AI analysis; newer file types not yet whitelisted in supported_attachment?; files with missing/misreported MIME content_type.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Content exceeds # character limit
- File access denied
- File is locked
- File not found
- No pageID or fileID provided
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/600c91eaf8b4807c.
Report an issue: GitHub.
Appendix: source
Thrown at app/services/study_assist.rb:174
def resolve_page(page_id)
page = @course.wiki_pages.not_deleted.find_by(url: page_id)
raise ContentUnavailable, "Page not found" if page.nil?
raise ContentUnavailable, "Page access denied" unless page.grants_right?(@user, :read)
shard_safe_key = shard_safe_cache_key_for(page)
text = Rails.cache.fetch(text_cache_key_for(:page, shard_safe_key), expires_in: TEXT_CACHE_TTL) do
html_to_text(page.body.to_s)
end
Content.new(kind: :page, id: page.id, cache_key_with_version: shard_safe_key, text:)
end
def resolve_file(file_id)
attachment = @course.attachments.find_by(id: file_id)
raise ContentUnavailable, "File not found" if attachment.nil? || attachment.deleted?
raise ContentUnavailable, "File access denied" unless attachment.grants_right?(@user, :read)
raise ContentUnavailable, "File is locked" if attachment.locked_for?(@user, check_policies: true)
raise UnsupportedContentType unless supported_attachment?(attachment)
raise ContentTooLarge, "File exceeds #{MAX_FILE_BYTES} byte limit" if attachment.size && attachment.size > MAX_FILE_BYTES
shard_safe_key = shard_safe_cache_key_for(attachment)
text = Rails.cache.fetch(text_cache_key_for(:file, shard_safe_key), expires_in: TEXT_CACHE_TTL) do
extract_attachment_text(attachment)
end
raise ContentUnavailable, "No text available for file" if text.blank?
Content.new(kind: :file, id: attachment.id, cache_key_with_version: shard_safe_key, text:)
end
def supported_attachment?(attachment)
return true if attachment.content_type&.start_with?("text/")
ACCEPTED_FILE_MIMETYPES.include?(attachment.content_type)
end
View on GitHub (pinned to 1c9f0bb801)