puppetlabs/puppet · error · ArgumentError

%{value} is not a valid day of the week

Error message

%{value} is not a valid day of the week

What it means

The schedule `weekday` parameter accepts integers 0–6 (0 = Sunday) or strings matching '0'-'6' or day-name/abbreviations (mon/monday, tues/tuesday, wed/wednesday, thurs/thursday, fri/friday, sat/saturday, sun/sunday, case-insensitive), per the validators in lib/puppet/type/schedule.rb:337. Anything else raises ArgumentError "is not a valid day of the week".

Source

Thrown at lib/puppet/type/schedule.rb:337

        of the range, not necessarily the day that it is when it matches.
        For example, consider this schedule:

            schedule { 'maintenance_window':
              range   => '22:00 - 04:00',
              weekday => 'Saturday',
            }

        This will match at 11 PM on Saturday and 2 AM on Sunday, but not
        at 2 AM on Saturday.
      EOT

      validate do |values|
        values = [values] unless values.is_a?(Array)
        values.each { |value|
          if weekday_integer?(value) || weekday_string?(value)
            value
          else
            raise ArgumentError, _("%{value} is not a valid day of the week") % { value: value }
          end
        }
      end

      def weekday_integer?(value)
        value.is_a?(Integer) && (0..6).cover?(value)
      end

      def weekday_string?(value)
        value.is_a?(String) && (value =~ /^[0-6]$/ || value =~ /^(Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur)?|Sun)(day)?$/i)
      end

      weekdays = {
        'sun' => 0,
        'mon' => 1,
        'tue' => 2,
        'wed' => 3,
        'thu' => 4,

View on GitHub (pinned to e227c27540)

Solutions

  1. Use 0–6 with 0 = Sunday, or day names/abbreviations ('Monday', 'mon')
  2. For 'every day', omit the weekday parameter entirely
  3. For cron-style 7 meaning Sunday, convert it to 0

Example fix

# before
schedule { 'nightly':
  weekday => '7',
}

# after
schedule { 'nightly':
  weekday => 'Sunday',
}
Defensive patterns

Strategy: validation

Validate before calling

if $weekday != undef {
  $ok = $weekday =~ /\A[0-6]\z/ or $weekday =~ /\A(Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur)?|Sun)(day)?\z/i
  unless $ok { fail("invalid weekday '${weekday}'") }
}

Type guard

def valid_weekday?(v)
  (v.is_a?(Integer) && (0..6).cover?(v)) ||
    (v.is_a?(String) && (v =~ /\A[0-6]\z/ ||
      v =~ /\A(Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur)?|Sun)(day)?\z/i))
end

Try / catch

begin
  Puppet::Type.type(:schedule).new(name: 'n', weekday: '7')
rescue ArgumentError => e
  raise unless e.message.include?('day of the week')
  # map 7 -> 0 or use a day name
end

Prevention

When it happens

Trigger: `weekday => '7'`; `weekday => 'all'`; integer 7 or -1; `weekday => 'lunes'`; arrays containing any of these (each element is checked).

Common situations: Assuming ISO 1–7 numbering (7=Sunday); trying to say 'every day'; localized day names; off-by-one from cron habits where 0 and 7 both mean Sunday.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21). Data as JSON: /api/errors/f9a44d237e4c6655. Report an issue: GitHub.