Freika/dawarich · error · Maps::BoundsCalculator::NoDateRangeError
No date range specified
Error message
No date range specified
What it means
Maps::BoundsCalculator::NoDateRangeError raised in validate_inputs! when start_date or end_date is nil. The bounds SQL uses `timestamp BETWEEN $2 AND $3`, so both ends of the range are mandatory; the validator rejects the call before touching the database. Note Ruby truthiness: an empty string '' passes this check and instead fails later in parse_date_parameter with invalid_date - only a truly absent/nil parameter triggers this error.
Source
Thrown at app/services/maps/bounds_calculator.rb:32
def call
validate_inputs!
start_timestamp = parse_date_parameter(@start_date)
end_timestamp = parse_date_parameter(@end_date)
bounds_result = execute_bounds_query(start_timestamp, end_timestamp)
point_count = bounds_result['point_count'].to_i
return build_no_data_response if point_count.zero?
build_success_response(bounds_result, point_count)
end
private
def validate_inputs!
raise NoUserFoundError, I18n.t('services.maps.bounds_calculator.no_user') unless @user
raise NoDateRangeError, I18n.t('services.maps.bounds_calculator.no_date_range') unless @start_date && @end_date
end
def execute_bounds_query(start_timestamp, end_timestamp)
ActiveRecord::Base.connection.exec_query(
"SELECT COUNT(*) as point_count,
ST_YMin(ST_Extent(lonlat::geometry)) as min_lat,
ST_YMax(ST_Extent(lonlat::geometry)) as max_lat,
ST_XMin(ST_Extent(lonlat::geometry)) as min_lng,
ST_XMax(ST_Extent(lonlat::geometry)) as max_lng
FROM points
WHERE user_id = $1
AND timestamp BETWEEN $2 AND $3",
'bounds_query',
[@user.id, start_timestamp, end_timestamp]
).first
end
def build_success_response(bounds_result, point_count)View on GitHub (pinned to 97fad417c5)
Solutions
- Supply both start_date and end_date - each may be a unix epoch integer, a digit-string, or a time string Time.zone.parse understands
- Fix the client to always send both parameters
- If a sensible default exists (e.g. first-of-month to today), default the values in the controller before calling the service
Example fix
# before Maps::BoundsCalculator.new(user: user, start_date: params[:start_at], end_date: params[:end_at]).call # params[:end_at] absent -> NoDateRangeError # after start_date = params[:start_at].presence || 30.days.ago.to_i end_date = params[:end_at].presence || Time.current.to_i Maps::BoundsCalculator.new(user: user, start_date: start_date, end_date: end_date).call
Defensive patterns
Strategy: validation
Validate before calling
# present? (not truthiness) also catches empty strings before they become invalid_date raise ArgumentError, 'start_date and end_date required' if start_date.blank? || end_date.blank?
Type guard
def complete_date_range?(start_date, end_date) !start_date.nil? && !end_date.nil? end
Try / catch
begin
Maps::BoundsCalculator.new(user: u, start_date: s, end_date: e).call
rescue Maps::BoundsCalculator::NoDateRangeError => e
render json: { error: e.message }, status: :bad_request
end Prevention
- Treat both dates as required params in the route/API contract and document it
- Send epoch integers from clients to skip string parsing entirely
- Use presence-based checks in callers - Ruby truthiness lets '' slip through to a different error
When it happens
Trigger: Calling the maps bounds API/service with start_date or end_date missing from the request, a caller passing nil explicitly, or frontend code firing the request before date pickers have been initialized so the params were never appended to the query string.
Common situations: Hand-crafted curl calls omitting params, URL builders that drop empty values, or clients assuming the service defaults to 'all time'.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- No user found
- Invalid tile coordinates
- Invalid date format: %{value}
- errorData.error || `Failed to ${isEdit ? "update" : "create"
- Failed to create visit
AI-assisted analysis of Freika/dawarich@97fad417c5 (2026-08-21).
Data as JSON: /api/errors/d5bd0f7eeb0054e8.
Report an issue: GitHub.