alexreisner/geocoder · error · RuntimeError
Please specify a CLASS (model)
Error message
Please specify a CLASS (model)
What it means
The geocoder:all rake task batch-geocodes records of a model, and reads the model class name from the CLASS environment variable. If CLASS (or class) is not set, it raises immediately because it has no model to geocode.
Solutions
- Run the task with the CLASS env var set to your model name: `rake geocoder:all CLASS=Venue`.
- Optionally add SLEEP, BATCH, LIMIT, REVERSE env vars as needed (e.g. CLASS=Venue BATCH=500).
- Check spelling/casing: the task accepts CLASS or class, nothing else.
- If invoking programmatically, pass ENV['CLASS'] before calling the rake task.
Example fix
// before bundle exec rake geocoder:all // after CLASS=Venue bundle exec rake geocoder:all
Defensive patterns
Strategy: validation
Validate before calling
# shell check before invoking the task
[ -n "$CLASS" ] || { echo "Usage: rake geocoder:all CLASS=MyModel"; exit 1; }
rake geocoder:all CLASS="$CLASS" Try / catch
begin Rake::Task['geocoder:all'].invoke rescue RuntimeError => e raise unless e.message == 'Please specify a CLASS (model)' warn 'Set the CLASS env var, e.g. rake geocoder:all CLASS=Venue' end
Prevention
- Always invoke the task as `rake geocoder:all CLASS=YourModel`; never rely on a default.
- Wrap the invocation in a script/Makefile target that validates CLASS is set first.
- Remember only CLASS or class (either case of this exact word) is read; MODEL or other names are ignored.
- In CI, export CLASS explicitly or fail fast with a usage message.
When it happens
Trigger: Running `rake geocoder:all` (or `bundle exec rake geocoder:all`) without CLASS=..., or misspelling the env var (e.g. `class=Venue` lowercase works, but `MODEL=Venue` does not), or setting it in the wrong shell/environment so it is empty.
Common situations: Developers migrating from other gems' rake tasks that use a different env var name; running the task from CI or a Procfile where env vars were not forwarded; forgetting the argument after copying the task name from docs.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- region_code '# ' is invalid. use one of #…
- Could not load geoip dependency. To use MaxMind Local…
- Could not load IP2Location DB dependency. To use the…
- Could not load Maxmind DB dependency. To use the GeoIP2…
- Error parsing # proxy URL: '#
AI-assisted analysis of alexreisner/geocoder@c10bd70121 (2026-09-15).
Data as JSON: /api/errors/f71abf7e8c200a19.
Report an issue: GitHub.
Appendix: source
Thrown at lib/tasks/geocoder.rake:11
require "geocoder/models/mongoid"
namespace :geocode do
desc "Geocode all objects without coordinates."
task :all => :environment do
class_name = ENV['CLASS'] || ENV['class']
sleep_timer = ENV['SLEEP'] || ENV['sleep']
batch = ENV['BATCH'] || ENV['batch']
reverse = ENV['REVERSE'] || ENV['reverse']
limit = ENV['LIMIT'] || ENV['limit']
raise "Please specify a CLASS (model)" unless class_name
klass = class_from_string(class_name)
batch = (batch.to_i unless batch.nil?) || 1000
orm = (klass < Geocoder::Model::Mongoid) ? 'mongoid' : 'active_record'
reverse = false unless reverse.to_s.downcase == 'true'
geocode_record = lambda { |obj|
reverse ? obj.reverse_geocode : obj.geocode
obj.save
sleep(sleep_timer.to_f) unless sleep_timer.nil?
}
scope = reverse ? klass.not_reverse_geocoded : klass.not_geocoded
scope = scope.limit(limit) if limit
if orm == 'mongoid'
scope.each do |obj|
geocode_record.call(obj)
end
elsif orm == 'active_record'View on GitHub (pinned to c10bd70121)