Freika/dawarich · error · ArgumentError
Unsupported file format: %{format}
Error message
Unsupported file format: %{format} What it means
Raised as ArgumentError by Exports::Create#build_export_tempfile when export.file_format is anything other than 'json' or 'gpx' (compared as symbols after to_sym). Only those two serializers exist; every other value falls to the else branch. The surrounding #call rescues it, marks the export failed with this message, and notifies the user.
Source
Thrown at app/services/exports/create.rb:48
safe_close.call(zipped_tempfile)
end
private
attr_reader :user, :export, :start_at, :end_at, :file_format
def time_framed_points
user
.points
.select(Point.column_names - %w[raw_data])
.where(timestamp: start_at.to_i..end_at.to_i)
end
def build_export_tempfile
case file_format.to_sym
when :json then Exports::PointGeojsonSerializer.new(time_framed_points).call
when :gpx then Exports::PointGpxSerializer.new(time_framed_points, export.name).call
else raise ArgumentError, I18n.t('services.exports.create.unsupported_file_format', format: file_format)
end
end
def notify_export_finished
I18n.with_locale(user.locale) do
Notifications::Create.new(
user:,
kind: :info,
title: I18n.t('services.exports.create.export_finished'),
content: I18n.t('services.exports.create.export_name_successfully_finished', name: export.name)
).call
end
end
def notify_export_failed(error)
I18n.with_locale(user.locale) do
Notifications::Create.new(
user:,View on GitHub (pinned to 97fad417c5)
Solutions
- Check the export's file_format value (Export.find(id).file_format) and correct it to 'json' or 'gpx'.
- Add an inclusion validation on Export.file_format (%w[json gpx]) so bad values are rejected at creation, not at job time.
- Normalize input (strip/downcase) when creating the export so 'GPX' or ' json' cannot be stored.
- If you need the format, implement an Exports::*Serializer and add a when branch.
Example fix
# before
Export.create!(file_format: 'csv') # later: ArgumentError: Unsupported file format: csv
# after
# app/models/export.rb
class Export < ApplicationRecord
validates :file_format, inclusion: { in: %w[json gpx] }
end
Export.create!(file_format: 'gpx') Defensive patterns
Strategy: validation
Validate before calling
EXPORT_FORMATS = %w[json gpx].freeze EXPORT_FORMATS.include?(export.file_format.to_s.downcase.strip) || raise(ArgumentError, 'unsupported export format')
Type guard
def supported_export_format?(f) = %w[json gpx].include?(f.to_s.downcase.strip)
Try / catch
begin Exports::Create.new(export:).call rescue ArgumentError => e export.update!(status: :failed, error_message: e.message) # already handled by service rescue end
Prevention
- Add an inclusion validation on Export.file_format so bad values never persist.
- Restrict the UI/API format dropdown to implemented serializers.
- Migrate or delete legacy rows when removing a format.
When it happens
Trigger: An Export record whose file_format column holds a legacy or hand-entered value ('csv', 'geojson', 'GPX ' with whitespace/case issues aside — note 'gpx'.to_sym is fine but 'GPX'.to_sym is :GPX and fails the case), or API clients creating exports with an unsupported format that DB/validation did not restrict.
Common situations: Old rows created before a format was removed, seeds/fixtures with arbitrary strings, direct SQL edits, enum-style validation missing on the Export model so any string reaches the service, or a new UI option shipped before its serializer.
Related errors
- zip has no entries
- errorData.error || `Failed to ${isEdit ? "update" : "create"
- Failed to create visit
- name
- latitude
AI-assisted analysis of Freika/dawarich@97fad417c5 (2026-08-21).
Data as JSON: /api/errors/6ada05d2dd63ed44.
Report an issue: GitHub.