instructure/canvas-lms · error · ResourceNotFoundError

Course not found

Error message

Course not found

What it means

For resource types 'CourseSyllabus' or 'Course', validate_resource_exists! treats resource_id as a course id and requires it to equal the course the service was constructed with. If they differ, ResourceNotFoundError 'Course not found' is raised — cross-course embeds cannot be validated/converted.

Solutions

  1. Pass the correct course when instantiating the service so course.id matches the embed's resource_id
  2. Use the current course's id as resource_id for CourseSyllabus/Course embeds
  3. Skip/re-route cross-course embeds to a service instance built for the owning course
  4. Re-run the scan for the correct course so keys reference its id

Example fix

// before
service = YoutubeMigrationService.new(new_course)
service.convert_embed(scan_id, { resource_type: 'CourseSyllabus', id: old_course.id, ... })
// after
service = YoutubeMigrationService.new(Course.find(resource_id))
service.convert_embed(scan_id, embed) # course.id == resource_id now
Defensive patterns

Strategy: try-catch

Validate before calling

if %w[CourseSyllabus Course].include?(embed[:resource_type]) && embed[:id] != course.id
  raise 'CourseSyllabus/Course embed belongs to a different course'
end

Try / catch

begin
  service.convert_embed(scan_id, embed)
rescue YoutubeMigrationService::ResourceNotFoundError => e
  Rails.logger.warn("cross-course embed skipped: #{e.message}")
end

Prevention

When it happens

Trigger: convert_embed on a syllabus/course embed whose resource_id points to a different course than YoutubeMigrationService.new(course) was initialized with.

Common situations: Copying syllabus content between courses; migrating a course and reusing old course ids; shard/shard-confusion where the id collides but belongs to another course; hard-coded ids from a previous environment.

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


AI-assisted analysis of instructure/canvas-lms@1c9f0bb801 (2026-09-15). Data as JSON: /api/errors/5bf3f57dade96427. Report an issue: GitHub.

Appendix: source

Thrown at app/services/youtube_migration_service.rb:210

    when "WikiPage"
      course.wiki_pages.find(resource_id)
    when "Assignment"
      course.assignments.find(resource_id)
    when "DiscussionTopic", "Announcement"
      course.discussion_topics.find(resource_id)
    when "DiscussionEntry"
      DiscussionEntry.find(resource_id)
    when "CalendarEvent"
      course.calendar_events.find(resource_id)
    when "Quizzes::Quiz"
      course.quizzes.find(resource_id)
    when "Quizzes::QuizQuestion"
      Quizzes::QuizQuestion.find(resource_id)
    when "AssessmentQuestion"
      AssessmentQuestion.find(resource_id)
    when "CourseSyllabus", "Course"
      # For syllabus, the resource_id is the course id
      raise ResourceNotFoundError, "Course not found" unless course.id == resource_id
    else
      raise ResourceNotFoundError, "Cannot validate existence for resource type: #{resource_type}"
    end
  rescue ActiveRecord::RecordNotFound
    raise ResourceNotFoundError, "Resource not found for type: #{resource_type}, id: #{resource_id}"
  end

  def convert_embed(scan_id, embed, user_uuid: nil)
    validate_scan_exists!(scan_id)
    validate_supported_resource!(embed[:resource_type])

    resource_group_key = embed[:resource_group_key] || YoutubeMigrationService.generate_resource_key(embed[:resource_type], embed[:id])
    validate_resource_group_key!(resource_group_key)
    validate_embed_exists_in_scan!(scan_id, embed)
    validate_resource_exists!(embed[:resource_type], embed[:id])

    message = YoutubeMigrationService.generate_resource_key(embed[:resource_type], embed[:id])
    # TODO: Something will listen on this creation

View on GitHub (pinned to 1c9f0bb801)