{"record":{"id":"24fdcd08f7e8abfc","repo":"instructure/canvas-lms","slug":"error-identifying-package-type-error","errorCode":null,"errorMessage":"Error identifying package type: %{error}","messagePattern":"Error identifying package type: %(.+?)","errorType":"exception","errorClass":"Canvas::Migration::Error","httpStatus":null,"severity":"error","filePath":"lib/canvas/migration/package_identifier.rb","lineNumber":95,"sourceCode":"        elsif has_namespace(doc, \"http://www.adlnet.org/xsd/adl_cp_rootv1p1\")\n          :scorm_1_1\n        elsif has_namespace(doc, \"http://www.adlnet.org/xsd/adlcp_rootv1p2\")\n          :scorm_1_2\n        elsif has_namespace(doc, \"http://www.adlnet.org/xsd/adlcp_v1p3\")\n          :scorm_1_3 # scorm 2004\n        elsif doc.at_css(\"resources resource[type^=ims_qti]\") ||\n              doc.at_css(\"resources resource[type^=imsqti]\")\n          :qti\n        else\n          # generic IMS Content Package?\n          :unknown_ims_cp_package\n        end\n      else\n        :unknown\n      end\n    rescue\n      # Not a valid archive file\n      raise Canvas::Migration::Error,\n            I18n.t(:package_error,\n                   \"Error identifying package type: %{error}\",\n                   error: $!.message),\n            $!.backtrace\n    end\n\n    private\n\n    # Common Cartridge 1.3 supports having just a single xml file\n    # if it's not CC 1.3 then we don't know how to handle it\n    def check_flat_xml_file\n      doc = create_xml_doc(File.read(@archive.file))\n      if get_node_val(doc, \"metadata schema\") =~ COMMON_CARTRIDGE_REGEX &&\n         get_node_val(doc, \"metadata schemaversion\") == \"1.3.0\"\n        :common_cartridge_1_3\n      else\n        :unknown\n      end","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/lib/canvas/migration/package_identifier.rb#L77-L113","documentation":"Canvas::Migration::PackageIdentifier#identify_package rescues any exception raised while probing a content package (zip/QTI/etc.) and re-raises it as Canvas::Migration::Error with the original message interpolated. It means the migration tool could not even determine what kind of package the uploaded file is.","triggerScenarios":"Calling Canvas::Migration::PackageIdentifier.identify_package on a corrupt archive, a non-zip file renamed to .zip/.imscc, an empty file, or a file unreadable by the archive library (Zip::Error, etc.).","commonSituations":"Users upload truncated exports, files uploaded mid-download, wrong file type uploaded in course copy/import UI, disk space issues corrupting temp extraction.","solutions":["Ask the user to re-export/re-upload the package; verify it opens as a valid zip","Check the interpolated error message ($!.message) for the underlying cause (e.g. Zip::Error vs ERB parse error)","Validate the file (unzip -t) before submitting it to the importer","Increase temp/disk availability on the app server if extraction failed from ENOSPC"],"exampleFix":"// before (caller, unguarded)\nconverter_class = Canvas::Migration::PackageIdentifier.identify_package(path)\n// after\nbegin\n  converter_class = Canvas::Migration::PackageIdentifier.identify_package(path)\nrescue Canvas::Migration::Error => e\n  flash[:error] = e.message\nend","handlingStrategy":"try-catch","validationCode":"raise 'not a zip' unless File.exist?(path) && File.open(path, 'rb') { |f| f.read(4) } == 'PK\\x03\\x04'","typeGuard":"def zip?(path)\n  File.file?(path) && File.size(path) > 0 && File.open(path, 'rb') { |f| f.read(4) } == 'PK\\x03\\x04'\nend","tryCatchPattern":"begin\n  type = Canvas::Migration::PackageIdentifier.identify_package(path)\nrescue Canvas::Migration::Error => e\n  errors.add(:package, e.message)\nend","preventionTips":["Verify the archive integrity (unzip -t) before import","Reject zero-byte or truncated uploads at the UI layer","Log the underlying cause message from the exception"],"tags":["content-migration","file","ruby"],"backgroundTag":"file-read-failed","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"}