{"record":{"id":"005d10c033cf4415","repo":"instructure/canvas-lms","slug":"no-content-importer-registered-for-context-type","errorCode":null,"errorMessage":"No content importer registered for #{context_type}","messagePattern":"No content importer registered for #(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/models/importers.rb","lineNumber":28,"sourceCode":"# Software Foundation, version 3 of the License.\n#\n# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY\n# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR\n# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more\n# details.\n#\n# You should have received a copy of the GNU Affero General Public License along\n# with this program. If not, see <http://www.gnu.org/licenses/>.\n\nmodule Importers\n  def self.register_content_importer(klass)\n    @content_importers ||= {}\n    @content_importers[klass.item_class.to_s] = klass\n  end\n\n  def self.content_importer_for(context_type)\n    klass = @content_importers&.[](context_type)\n    raise \"No content importer registered for #{context_type}\" unless klass\n\n    klass\n  end\n\n  def self.disable_live_events!\n    ActiveRecord::Base.observers.disable LiveEventsObserver\n    yield\n  ensure\n    enable_live_events!\n  end\n\n  def self.enable_live_events!\n    ActiveRecord::Base.observers.enable LiveEventsObserver\n  end\n\n  class Importer\n    class << self\n      attr_accessor :item_class","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/instructure/canvas-lms/blob/1c9f0bb8013ed69c4f2efe11fd483025469b7e6c/app/models/importers.rb#L10-L46","documentation":"Canvas maintains a registry of content importers keyed by the importer class's item_class name (registered via ContentImporter.register). content_importer_for looks up the registry by context_type string and raises when no importer has been registered under that key, meaning the requested context type has no importer capable of handling the migration.","triggerScenarios":"Calling Importers.content_importer_for(context_type) with a context_type string that no importer registered — a typo, an unsupported context class, or the importer class never being loaded (e.g. in a context where plugin importers aren't required).","commonSituations":"Content migration requests targeting an account/course context whose importer plugin isn't installed; passing 'User' or another non-importable context; refactors renaming item_class so the registry key no longer matches the lookup string.","solutions":["Check the exact context_type string passed and compare it to registered keys (Importers.content_importers or the register calls in app/models/importers/*.rb)","Ensure the importer class for that context is defined and loaded before lookup (eager_load / require the file)","If the context type genuinely isn't importable, guard the call site and handle the unsupported type instead of raising","For plugin-provided importers, verify the plugin is installed and enabled on the shard/account"],"exampleFix":"// before\nklass = Importers.content_importer_for(context_type)\n// after\nklass = Importers.content_importer_for(context_type) rescue nil\nreturn render_error('unsupported content type') unless klass","handlingStrategy":"validation","validationCode":"registered = Importers.content_importers rescue {}\nraise 'unsupported context type' unless registered.key?(context_type)","typeGuard":"def importable_context?(context_type)\n  Importers.content_importer_for(context_type)\nrescue RuntimeError\n  false\nend","tryCatchPattern":"begin\n  klass = Importers.content_importer_for(context_type)\nrescue RuntimeError => e\n  render json: { error: \"no importer for #{context_type}\" }, status: :bad_request\nend","preventionTips":["Centralize context_type constants instead of passing raw strings","Ensure importer files are eager-loaded in all environments","Cover every supported context type with a lookup test"],"tags":["ruby","import","registry","canvas"],"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"}