{"record":{"id":"a91f61bfcfd73b36","repo":"instructure/canvas-lms","slug":"resource-not-found-in-scan-for-key-resource-group-key","errorCode":null,"errorMessage":"Resource not found in scan for key: #{resource_group_key}","messagePattern":"Resource not found in scan for key: #(.+?)","errorType":"exception","errorClass":"EmbedNotFoundError","httpStatus":404,"severity":"error","filePath":"app/services/youtube_migration_service.rb","lineNumber":153,"sourceCode":"\n  def initialize(course)\n    self.course = course\n  end\n\n  def validate_scan_exists!(scan_id)\n    YoutubeMigrationService.find_scan(course, scan_id)\n  rescue ActiveRecord::RecordNotFound\n    raise EmbedNotFoundError, \"Scan not found for id: #{scan_id}\"\n  end\n\n  def validate_embed_exists_in_scan!(scan_id, embed)\n    scan = YoutubeMigrationService.find_scan(course, scan_id)\n    resource_group_key = resource_group_key_for(embed)\n\n    return if scan.results.blank? || scan.results[:resources].blank?\n\n    resource = scan.results[:resources][resource_group_key]\n    raise EmbedNotFoundError, \"Resource not found in scan for key: #{resource_group_key}\" if resource.blank?\n\n    embed_exists = resource[:embeds].any? do |scan_embed|\n      scan_embed[:src] == embed[:src] &&\n        scan_embed[:field].to_s == embed[:field].to_s &&\n        scan_embed[:resource_type] == embed[:resource_type]\n    end\n\n    raise EmbedNotFoundError, \"Embed not found in scan for resource: #{resource_group_key}\" unless embed_exists\n  end\n\n  def prepare_new_quiz_resource_type(resource_type)\n    case resource_type\n    when /QuizzesNext::Quiz/\n      \"QuizzesNext::Quiz\"\n    when /QuizzesNext::Bank/\n      \"QuizzesNext::Bank\"\n    else\n      resource_type","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/services/youtube_migration_service.rb#L135-L171","documentation":"After locating the scan, validate_embed_exists_in_scan! checks scan.results[:resources] for the embed's resource_group_key. If the scan results have no entry for that key, EmbedNotFoundError is raised, meaning the embed's resource was never captured (or results were trimmed) during the scan phase.","triggerScenarios":"convert_embed called with an embed whose resource_group_key (type|id) is absent from the scan's results hash, including when the resources hash itself is blank but total results exist for other keys.","commonSituations":"Embed added to the content after the scan ran; scan results truncated or partially saved; wrong resource_type/id embedded so the computed key doesn't match; results reset by a re-scan in progress.","solutions":["Re-run the youtube embed scan so results include the new/changed resource","Confirm the embed hash's resource_type and id match what the scan recorded (key format 'Type|id')","Inspect scan.results[:resources].keys to see which keys the scan actually captured","Ensure conversion is not racing an in-progress re-scan that reset results"],"exampleFix":"// before\nservice.convert_embed(scan_id, { resource_type: 'Assignment', id: bad_id, src: url })\n// after\nscan = YoutubeMigrationService.find_scan(course, scan_id)\nkey = \"Assignment|#{assignment.id}\"\nif scan.results[:resources].blank? || scan.results[:resources][key.to_sym].blank?\n  YoutubeMigrationService.run_scan(course) # refresh results\nend\nservice.convert_embed(scan_id, embed)","handlingStrategy":"validation","validationCode":"key = \"#{embed[:resource_type]}|#{embed[:id]}\"\nscan = YoutubeMigrationService.find_scan(course, scan_id)\nraise 'resource missing from scan; re-scan required' if scan.results.blank? || scan.results.dig(:resources, key.to_sym).blank?","typeGuard":null,"tryCatchPattern":"begin\n  service.convert_embed(scan_id, embed)\nrescue YoutubeMigrationService::EmbedNotFoundError\n  YoutubeMigrationService.run_scan(course)\n  service.convert_embed(scan_id, embed)\nend","preventionTips":["Re-scan after any content edit before converting","Convert promptly after scanning; don't let results go stale","Verify resource_type/id values exactly match what the scan recorded"],"tags":["ruby","migration","resource-not-found","scan-results"],"backgroundTag":"resource-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"}