instructure/canvas-lms · error · ImportError

Invalid course_format "#

Error message

Invalid course_format "#{course_format}" for course #{course_id}

What it means

SisCourseImporter#add_course raises ImportError when course_format is non-blank and does not match /\A(online|on_campus|blended|not_set)/i. course_format is an optional column; if provided it must be one of Canvas's four recognized course formats.

Solutions

  1. Map source-system delivery modes to one of online|on_campus|blended|not_set before import
  2. Leave the course_format column blank if the value is unknown — blank is explicitly accepted
  3. Normalize values to lowercase and strip whitespace; remember leading whitespace fails the \A-anchored match
  4. Pre-validate the CSV: allow only blank or the four enum values

Example fix

// before
format = row["delivery"] # "hybrid"
// after
format = {"hybrid"=>"blended", "in-person"=>"on_campus", "web"=>"online"}.fetch(row["delivery"].to_s.strip.downcase, "not_set")
Defensive patterns

Strategy: validation

Validate before calling

fmt = row['course_format'].to_s.strip
raise ArgumentError, "bad course_format #{fmt}" unless fmt.empty? || fmt.downcase.match?(/\A(online|on_campus|blended|not_set)/)

Type guard

def valid_course_format?(f) = f.to_s.strip.empty? || %w[online on_campus blended not_set].any? { |v| f.to_s.strip.downcase.start_with?(v) }

Try / catch

begin
  importer.add_course(...)
rescue SisImport::ImportError => e
  raise unless e.message.start_with?('Invalid course_format')
  log.warn("normalizing course_format and retrying: #{e.message}")
end

Prevention

When it happens

Trigger: add_course called with course_format like "web", "hybrid", "face_to_face", "online_course", or a leading-space value (\A anchor makes " online" fail). Any non-empty value outside the four-option enum triggers it.

Common situations: Institutions exporting their own LMS course-delivery labels (hybrid, in-person, web-enhanced) directly into the SIS file; case handled fine (case-insensitive) but synonyms are not; optional column filled with placeholder text like "TBD".

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at lib/sis/course_importer.rb:70

        @batch = batch
        @batch_user = batch_user
        @root_account = root_account
        @courses_to_update_sis_batch_id = a1
        @course_ids_to_update_associations = a2
        @roll_back_data = []
        @blueprint_associations = blueprint_associations
        @messages = m
        @logger = logger
        @success_count = 0
      end

      def add_course(course_id, term_id, account_id, fallback_account_id, status, start_date, end_date, abstract_course_id, short_name, long_name, integration_id, course_format, blueprint_course_id, grade_passback_setting, homeroom_course, friendly_name)
        state_changes = []
        raise ImportError, "No course_id given for a course" if course_id.blank?
        raise ImportError, "No short_name given for course #{course_id}" if short_name.blank? && abstract_course_id.blank?
        raise ImportError, "No long_name given for course #{course_id}" if long_name.blank? && abstract_course_id.blank?
        raise ImportError, "Improper status \"#{status}\" for course #{course_id}" unless /\A(active|deleted|completed|unpublished|published)/i.match?(status)
        raise ImportError, "Invalid course_format \"#{course_format}\" for course #{course_id}" unless course_format.blank? || course_format =~ /\A(online|on_campus|blended|not_set)/i

        valid_grade_passback_settings = %w[nightly_sync disabled not_set]
        raise ImportError, "Invalid grade_passback_setting \"#{grade_passback_setting}\" for course #{course_id}" unless grade_passback_setting.blank? || valid_grade_passback_settings.include?(grade_passback_setting.downcase.strip)
        return if @batch.skip_deletes? && status =~ /deleted/i

        Course.unique_constraint_retry do
          course = @root_account.all_courses.find_by(sis_source_id: course_id)
          if course.nil?
            course = Course.new
            state_changes << :created
          else
            state_changes << :updated
          end
          course.saved_by = :sis_import
          course_enrollment_term_id_stuck = course.stuck_sis_fields.include?(:enrollment_term_id)
          if !course_enrollment_term_id_stuck && term_id
            term = @root_account.enrollment_terms.active.find_by(sis_source_id: term_id)
          end

View on GitHub (pinned to 1c9f0bb801)