{"record":{"id":"dc08c5852b10b2c5","repo":"instructure/canvas-lms","slug":"page-not-found","errorCode":null,"errorMessage":"Page not found","messagePattern":"Page not found","errorType":"validation","errorClass":"ContentUnavailable","httpStatus":null,"severity":"error","filePath":"app/services/study_assist.rb","lineNumber":158,"sourceCode":"      content =\n        if page_id.present?\n          resolve_page(page_id)\n        elsif file_id.present?\n          resolve_file(file_id)\n        else\n          raise ContentUnavailable, \"No pageID or fileID provided\"\n        end\n\n      if content.text.length > MAX_CONTENT_CHARS\n        raise ContentTooLarge, \"Content exceeds #{MAX_CONTENT_CHARS} character limit\"\n      end\n\n      content\n    end\n\n    def resolve_page(page_id)\n      page = @course.wiki_pages.not_deleted.find_by(url: page_id)\n      raise ContentUnavailable, \"Page not found\" if page.nil?\n      raise ContentUnavailable, \"Page access denied\" unless page.grants_right?(@user, :read)\n\n      shard_safe_key = shard_safe_cache_key_for(page)\n      text = Rails.cache.fetch(text_cache_key_for(:page, shard_safe_key), expires_in: TEXT_CACHE_TTL) do\n        html_to_text(page.body.to_s)\n      end\n\n      Content.new(kind: :page, id: page.id, cache_key_with_version: shard_safe_key, text:)\n    end\n\n    def resolve_file(file_id)\n      attachment = @course.attachments.find_by(id: file_id)\n      raise ContentUnavailable, \"File not found\" if attachment.nil? || attachment.deleted?\n      raise ContentUnavailable, \"File access denied\" unless attachment.grants_right?(@user, :read)\n      raise ContentUnavailable, \"File is locked\" if attachment.locked_for?(@user, check_policies: true)\n      raise UnsupportedContentType unless supported_attachment?(attachment)\n      raise ContentTooLarge, \"File exceeds #{MAX_FILE_BYTES} byte limit\" if attachment.size && attachment.size > MAX_FILE_BYTES\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/study_assist.rb#L140-L176","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nStudyAssist.new(course: @course, user: @user, prompt:, page_id: page.id).call\n// after\nStudyAssist.new(course: @course, user: @user, prompt:, page_id: page.url).call","handlingStrategy":"validation","validationCode":"page = course.wiki_pages.not_deleted.find_by(url: page_id)\nraise StudyAssist::ContentUnavailable, 'Page not found' if page.nil?","typeGuard":"null","tryCatchPattern":"begin\n  StudyAssist.new(course:, user:, prompt:, page_id: page_id).call\nrescue StudyAssist::ContentUnavailable => e\n  render json: { error: e.message }, status: :not_found\nend","preventionTips":["Pass the page url slug, not numeric ID","Verify page existence/non-deleted state before calling","Ensure page_id belongs to the same course"],"tags":["ruby","study-assist","not-found","wiki-page"],"backgroundTag":"record-not-found","analyzedSha":"1c9f0bb8013ed69c4f2efe11fd483025469b7e6c","analyzedAt":"2026-09-15T20:33:18.891Z","contentChangedAt":"2026-09-15T20:33:18.891Z","schemaVersion":2},"datasetVersion":"2026-09-23T02:17:17.105Z"}