Freika/dawarich · error · ArgumentError

Import source cannot be nil

Error message

Import source cannot be nil

What it means

Raised as ArgumentError by Imports::Create#importer when the import has no usable source: import.source is blank/whitespace AND detect_source_from_file (Imports::SourceDetector via new_from_file_header + detect_source!) returned nil — i.e. the file's magic bytes/header matched no known format. The dispatcher has no importer class to instantiate, so it fails before reading any points.

Source

Thrown at app/services/imports/create.rb:97

        user:,
        kind: :warning,
        title: I18n.t('services.imports.create.import_post_processing_incomplete'),
        content: I18n.t('services.imports.create.your_import_name_finished_and_all_points_were_saved_but',
                        name: import.name, step: step.tr('_', ' '))
      ).call
    end
  rescue StandardError => e
    ExceptionReporter.call(e, 'Failed to create post-import failure notification')
  end

  def run_importer(path)
    source = import.source.presence || detect_source_from_file(path)
    import.update!(source: source) if import.source.to_s != source.to_s
    importer(source).new(import, user.id, path).call
  end

  def importer(source)
    raise ArgumentError, I18n.t('services.imports.create.source_missing') if source.nil?

    case source.to_s
    when 'google_semantic_history'      then GoogleMaps::SemanticHistoryImporter
    when 'google_phone_takeout'         then GoogleMaps::PhoneTakeoutImporter
    when 'google_records'               then GoogleMaps::RecordsStorageImporter
    when 'google_photos'                then GooglePhotos::Importer
    when 'owntracks'                    then OwnTracks::Importer
    when 'gpx'                          then Gpx::TrackImporter
    when 'kml'                          then Kml::Importer
    when 'geojson'                      then Geojson::Importer
    when 'immich_api', 'photoprism_api' then Photos::Importer
    when 'csv'                          then Csv::Importer
    when 'tcx'                          then Tcx::Importer
    when 'fit'                          then Fit::Importer
    when 'polarsteps'                   then Polarsteps::Importer
    when 'zip'
      raise ArgumentError, I18n.t('services.imports.create.zip_unclassified')
    else

View on GitHub (pinned to 97fad417c5)

Solutions

  1. Re-upload and explicitly pick the source in the import form instead of relying on auto-detection.
  2. Verify the file opens in its native app and has the expected extension-vs-content match (unzip -l for archives, head -c 200 for plain files).
  3. If the format is genuinely unsupported, convert it to a supported one (GPX/GeoJSON/CSV) with gpsbabel or similar before importing.
  4. For empty/corrupt uploads, check upload size limits and retry the transfer.

Example fix

# before: auto-detect only
import.update!(source: nil)
Imports::Create.new(user, import).call # detect_source! -> nil -> ArgumentError

# after: set the source explicitly on create
import.update!(source: 'gpx')
Imports::Create.new(user, import).call
Defensive patterns

Strategy: validation

Validate before calling

source = import.source.presence || Imports::SourceDetector.new_from_file_header(path).detect_source!
source.present? || raise(ArgumentError, 'Unknown file type - select the import source manually')

Type guard

def known_import_source?(s) = %w[google_semantic_history google_phone_takeout google_records google_photos owntracks gpx kml geojson immich_api photoprism_api csv tcx fit polarsteps].include?(s.to_s)

Try / catch

begin
  Imports::Create.new(user, import).call
rescue ArgumentError => e
  import.update!(status: :failed, error_message: 'Could not detect the file type. Choose the source manually and retry.')
end

Prevention

When it happens

Trigger: Uploading a file format the detector does not recognize (e.g. an obscure tracker's binary export, a corrupted zip whose header is unreadable, an empty 0-byte file) without manually selecting a source; or a user choosing 'auto-detect' for a format outside the supported list (google takeout variants, owntracks, gpx, kml, geojson, immich/photoprism api, csv, tcx, fit, polarsteps).

Common situations: Renamed files (.gpx extension on JSON contents), uploads truncated so the header signature is missing, encrypted/password-protected zips whose inner header cannot be sniffed, brand-new formats users assume are supported.

Related errors


AI-assisted analysis of Freika/dawarich@97fad417c5 (2026-08-21). Data as JSON: /api/errors/f7e715378a3bdb20. Report an issue: GitHub.