puppetlabs/puppet · error · Puppet::Settings::ValidationError

Invalid duration format '%{value}' for parameter: %{name}

Error message

Invalid duration format '%{value}' for parameter: %{name}

What it means

Puppet::Settings::DurationSetting#munge converts duration settings (runinterval, http_keepalive_timeout, ...) to seconds. Accepted inputs are Integers/nil or Strings matching ^(\d+)(y|d|h|m|s)?$ — a number plus at most ONE single-letter unit. Multi-unit strings (1h30m), decimals (1.5h), negatives, spaces (90 s), or long unit names (10minutes, 5min, 500ms) raise Puppet::Settings::ValidationError.

Source

Thrown at lib/puppet/settings/duration_setting.rb:30

    "m" => 60,
    "s" => 1
  }

  # A regex describing valid formats with groups for capturing the value and units
  FORMAT = /^(\d+)(y|d|h|m|s)?$/

  def type
    :duration
  end

  # Convert the value to an integer, parsing numeric string with units if necessary.
  def munge(value)
    if value.is_a?(Integer) || value.nil?
      value
    elsif value.is_a?(String) and value =~ FORMAT
      ::Regexp.last_match(1).to_i * UNITMAP[::Regexp.last_match(2) || 's']
    else
      raise Puppet::Settings::ValidationError, _("Invalid duration format '%{value}' for parameter: %{name}") % { value: value.inspect, name: @name }
    end
  end
end

View on GitHub (pinned to e227c27540)

Solutions

  1. Use a bare integer of seconds (runinterval = 600) or number + single letter: 10m, 2h, 1d, 1y.
  2. Convert compound durations yourself before writing config (1h30m -> 90m or 5400).
  3. Milliseconds are not supported — convert ms values to seconds (500ms -> 0.5 is invalid; use 1 or restructure).

Example fix

# before (puppet.conf [agent])
runinterval = 10minutes

# after
runinterval = 10m
Defensive patterns

Strategy: validation

Validate before calling

raise ArgumentError, "bad duration #{v.inspect}" unless v.is_a?(Integer) || v.to_s.match?(/^(\d+)(y|d|h|m|s)?$/)
Puppet.settings[:runinterval] = v

Type guard

valid_duration = ->(v) { v.is_a?(Integer) || v.to_s.match?(/^(\d+)(y|d|h|m|s)?$/) }

Try / catch

begin
  Puppet.settings[:runinterval] = v
rescue Puppet::Settings::ValidationError => e
  raise unless e.message.include?('duration')
  Puppet.err("#{e.message} — use integer seconds or Ns/Nm/Nh/Nd/Ny")
  raise
end

Prevention

When it happens

Trigger: puppet.conf `runinterval = 10minutes`, `runinterval = 1.5h`, `runinterval = 1h30m`, or `runinterval = 500ms`; programmatic Puppet.settings[:runinterval] = '90 s'; values copied from systemd/nginx configs.

Common situations: Expecting millisecond support (the smallest unit is s); copying time formats across tools; templated configs generating compound durations.

Related errors


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