instructure/canvas-lms · error · ContentUnavailable
Page not found
Error message
Page not found
What it means
StudyAssist::ContentUnavailable with 'Page not found' is raised by resolve_page when @course.wiki_pages.not_deleted.find_by(url: page_id) returns nil. The page_id is treated as a wiki page URL slug; a non-matching or deleted page yields no record.
Solutions
- Pass the wiki page's url slug (not its numeric ID) as page_id
- Confirm the page exists and is not deleted in the target course
- Verify the page_id originates from the same @course the service is constructed with
- Query WikiPage.not_deleted.where(url: page_id) in console to debug the lookup
Example fix
// before StudyAssist.new(course: @course, user: @user, prompt:, page_id: page.id).call // after StudyAssist.new(course: @course, user: @user, prompt:, page_id: page.url).call
Defensive patterns
Strategy: validation
Validate before calling
page = course.wiki_pages.not_deleted.find_by(url: page_id) raise StudyAssist::ContentUnavailable, 'Page not found' if page.nil?
Type guard
null
Try / catch
begin
StudyAssist.new(course:, user:, prompt:, page_id: page_id).call
rescue StudyAssist::ContentUnavailable => e
render json: { error: e.message }, status: :not_found
end Prevention
- Pass the page url slug, not numeric ID
- Verify page existence/non-deleted state before calling
- Ensure page_id belongs to the same course
When it happens
Trigger: Calling #call with page_id that doesn't match any non-deleted wiki page's url in the course (typo'd slug, page deleted, page belongs to another course, or a numeric ID passed where a URL slug is expected).
Common situations: Frontend passes the page's numeric ID instead of its url slug; stale client cache referencing a deleted page; cross-course copy where the slug differs; hidden/wiki pages with different url attribute than title.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- File not found
- An old_id, '# ', referenced a non-existent # and was not…
- An old_integration_id, '#
- Content exceeds # character limit
- Course does not exist
AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15).
Data as JSON: /api/errors/dc08c5852b10b2c5.
Report an issue: GitHub.
Appendix: source
Thrown at app/services/study_assist.rb:158
content =
if page_id.present?
resolve_page(page_id)
elsif file_id.present?
resolve_file(file_id)
else
raise ContentUnavailable, "No pageID or fileID provided"
end
if content.text.length > MAX_CONTENT_CHARS
raise ContentTooLarge, "Content exceeds #{MAX_CONTENT_CHARS} character limit"
end
content
end
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
View on GitHub (pinned to 1c9f0bb801)