{"record":{"id":"093faebb0be60a1b","repo":"javan/whenever","slug":"must-be-between-at-max-given","errorCode":null,"errorMessage":"#{must_be_between}, #{at.max} given","messagePattern":"#(.+?), #(.+?) given","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/whenever/cron.rb","lineNumber":157,"sourceCode":"        timing = Array.new(4, '*')\n        timing[0] = @at.is_a?(Time) ? @at.min  : 0\n        timing[1] = @at.is_a?(Time) ? @at.hour : 0\n\n        return (timing << '1-5') * \" \" if string.downcase.index('weekday')\n        return (timing << '6,0') * \" \" if string.downcase.index('weekend')\n\n        DAYS.each_with_index do |day, i|\n          return (timing << i) * \" \" if string.downcase.index(day)\n        end\n\n        raise ArgumentError, \"Couldn't parse: #{@time.inspect}\"\n      end\n\n      def range_or_integer(at, valid_range, name)\n        must_be_between = \"#{name} must be between #{valid_range.min}-#{valid_range.max}\"\n        if at.is_a?(Range)\n          raise ArgumentError, \"#{must_be_between}, #{at.min} given\" unless valid_range.include?(at.min)\n          raise ArgumentError, \"#{must_be_between}, #{at.max} given\" unless valid_range.include?(at.max)\n          return \"#{at.min}-#{at.max}\"\n        end\n        raise ArgumentError, \"#{must_be_between}, #{at} given\" unless valid_range.include?(at)\n        at\n      end\n\n      def comma_separated_timing(frequency, max, start = 0)\n        return start     if frequency.nil? || frequency == \"\" || frequency.zero?\n        return '*'       if frequency == 1\n        return frequency if frequency > (max * 0.5).ceil\n\n        original_start = start\n\n        start += frequency unless (max + 1).modulo(frequency).zero? || start > 0\n        output = (start..max).step(frequency).to_a\n\n        max_occurances = (max.to_f  / (frequency.to_f)).round\n        max_occurances += 1 if original_start.zero?","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/javan/whenever/blob/756163ed1aa928c8abd629aa2f4904bc5226538c/lib/whenever/cron.rb#L139-L175","documentation":"Whenever validates the :at option for numeric frequencies against the cron field it controls. When :at is a Ruby Range whose end (at.max) falls outside the field's legal values, range_or_integer raises ArgumentError naming the field, its bounds, and the offending max. Ruby Range ends are inclusive, so (0..24) really does include 24 — one past cron's hour ceiling.","triggerScenarios":"every 1.day, at: (9..24) → Hour must be between 0-23, 24 given (24:00 does not exist in cron; use 0 for midnight). every 1.hour, at: (0..60) → Minute must be between 0-59, 60 given. every 1.year, at: (1..13) → Month must be between 1-12, 13 given.","commonSituations":"Treating 24 as 'end of day' when cron wraps 24 back to 0; half-open interval habits from other languages producing inclusive ends one past the limit; generated schedules whose upper bound is computed rather than hardcoded.","solutions":["Cap the Range end at the field maximum: hours (0..23), minutes (0..59), days (1..31), months (1..12).","For a time span crossing the boundary (e.g. 22:00 to midnight), use a Chronic string or raw cron instead of a numeric Range.","Add a schedule-generation smoke test (run `whenever` with no flags) to CI so out-of-bounds ends are caught before deploy."],"exampleFix":"# before (24:00 is not a valid cron hour)\nevery 1.day, at: (9..24) do\n  rake 'nightly:job'\nend\n\n# after\nevery 1.day, at: (9..23) do\n  rake 'nightly:job'\nend","handlingStrategy":"validation","validationCode":"LIMITS = { minute: 0..59, hour: 0..23, day: 1..31, month: 1..12 }\n# before: every 1.day, at: (9..24)\nat = (9..24); field = :hour\nunless LIMITS[field].cover?(at.max)\n  abort(field.to_s + ' range must end within ' + LIMITS[field].to_s + ' (cron has no 24:00)')\nend","typeGuard":"def valid_at_range?(at, field)\n  limits = { minute: 0..59, hour: 0..23, day: 1..31, month: 1..12 }\n  at.is_a?(Range) && limits[field].cover?(at.min) && limits[field].cover?(at.max)\nend","tryCatchPattern":"begin\n  Whenever.cron(file: 'config/schedule.rb')\nrescue ArgumentError => e\n  abort('invalid :at range end in schedule: ' + e.message)\nend","preventionTips":["Remember Ruby Range ends are inclusive — (0..24) includes the invalid hour 24; use 0 for midnight.","Compute upper bounds with .min(bound) or an explicit clamp before passing them.","Dry-run generated schedules in CI to catch off-by-one range ends."],"tags":["ruby","cron","scheduling","range-validation","argumenterror"],"backgroundTag":"cron-field-out-of-range","analyzedSha":"756163ed1aa928c8abd629aa2f4904bc5226538c","analyzedAt":"2026-08-21T18:07:39.974Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}