{"record":{"id":"c32da336fb14e4c3","repo":"Freika/dawarich","slug":"invalid-date-format-value","errorCode":null,"errorMessage":"Invalid date format: %{value}","messagePattern":"Invalid date format: %(.+?)","errorType":"http","errorClass":"ArgumentError","httpStatus":400,"severity":"error","filePath":"app/services/maps/bounds_calculator.rb","lineNumber":78,"sourceCode":"      }\n    end\n\n    def build_no_data_response\n      {\n        success: false,\n        error: I18n.t('services.maps.bounds_calculator.no_data_found_for_the_specified_date_range'),\n        point_count: 0\n      }\n    end\n\n    def parse_date_parameter(param)\n      case param\n      when String\n        if param.match?(/^\\d+$/)\n          param.to_i\n        else\n          parsed_time = Time.zone.parse(param)\n          raise ArgumentError, I18n.t('services.maps.bounds_calculator.invalid_date', value: param) if parsed_time.nil?\n\n          parsed_time.to_i\n        end\n      when Integer\n        param\n      else\n        param.to_i\n      end\n    rescue ArgumentError => e\n      Rails.logger.error \"Invalid date format: #{param} - #{e.message}\"\n      raise ArgumentError, I18n.t('services.maps.bounds_calculator.invalid_date', value: param)\n    end\n  end\nend\n","sourceCodeStart":60,"sourceCodeEnd":93,"githubUrl":"https://github.com/Freika/dawarich/blob/97fad417c5a11b0eb11157890635e015723a2e97/app/services/maps/bounds_calculator.rb#L60-L93","documentation":"ArgumentError raised inside parse_date_parameter when a String date parameter is not purely digits and Time.zone.parse returns nil - ActiveSupport could not interpret it as a datetime at all. The %{value} placeholder carries the offending string. Note this raise happens inside a method that immediately rescues ArgumentError and re-raises from line 89, so the observable failure is the identical invalid_date message from the rescue clause.","triggerScenarios":"Passing date strings like 'not-a-date', '2024-13-01' (month 13 makes parse return nil in many zones), 'YYYY/MM/DD' variants ActiveSupport cannot resolve, or URL-encoding damage that mangles the parameter. Digit strings ('1717200000') and Integers never hit this path.","commonSituations":"Hand-crafted API calls, locale-specific formats (DD/MM/YYYY vs MM/DD/YYYY ambiguity), or test fixtures using placeholder strings like 'foo'.","solutions":["Send dates as unix epoch timestamps (integer or digit-only string) - the unambiguous fast path","Or use ISO 8601 strings like '2024-06-01T00:00:00Z' that Time.zone.parse always handles","Validate/normalize date inputs on the client before issuing the request","Rescue ArgumentError at the controller and return 400 with the message rather than letting it bubble as 500"],"exampleFix":"# before\ncalculator = Maps::BoundsCalculator.new(user: u, start_date: 'June 1 2024', end_date: 'todayish')\n\n# after\ncalculator = Maps::BoundsCalculator.new(user: u, start_date: 1717200000, end_date: 1719791999)","handlingStrategy":"validation","validationCode":"def parseable_bound_date?(value)\n  case value\n  when Integer then true\n  when String then value.match?(/\\A\\d+\\z/) || !Time.zone.parse(value).nil?\n  else false\n  end\nend\n\nraise ArgumentError, \"bad date #{start_date}\" unless parseable_bound_date?(start_date)","typeGuard":"def epoch_or_iso?(value)\n  value.is_a?(Integer) || value.to_s.match?(/\\A\\d+\\z\\z/) || value.to_s.match?(\\A\\d{4}-\\d{2}-\\d{2}(T[\\d:.]+Z)?\\z/)\nend","tryCatchPattern":"begin\n  result = Maps::BoundsCalculator.new(user: u, start_date: s, end_date: e).call\nrescue ArgumentError => e\n  render json: { error: e.message }, status: :bad_request  # message includes the offending %{value}\nend","preventionTips":["Send unix epoch integers - the digit-string/Integer fast path never parses","Otherwise use ISO 8601 ('2024-06-01T00:00:00Z')","Validate in the client with the same contract before issuing the request"],"tags":["maps","date-parsing","argument-error","bounds"],"backgroundTag":"invalid-date-format","analyzedSha":"97fad417c5a11b0eb11157890635e015723a2e97","analyzedAt":"2026-08-21T17:04:17.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}