puppetlabs/puppet · error · ArgumentError

try_sleep must be a number

Error message

try_sleep must be a number

What it means

The exec type's `try_sleep` parameter (seconds to sleep between retries, munged with Float()) first requires String values to match /^[-\d.]+$/ . A string containing any other character — letters, commas, whitespace, or unit suffixes — raises ArgumentError 'try_sleep must be a number' before Float() is attempted.

Source

Thrown at lib/puppet/type/exec.rb:374

          end

          value = Integer(value)
        end
        raise ArgumentError, _("Tries must be an integer >= 1") if value < 1

        value
      end

      defaultto 1
    end

    newparam(:try_sleep) do
      desc "The time to sleep in seconds between 'tries'."

      munge do |value|
        if value.is_a?(String)
          unless value =~ /^[-\d.]+$/
            raise ArgumentError, _("try_sleep must be a number")
          end

          value = Float(value)
        end
        raise ArgumentError, _("try_sleep cannot be a negative number") if value < 0

        value
      end

      defaultto 0
    end

    newcheck(:refreshonly) do
      desc <<-'EOT'
        The command should only be run as a
        refresh mechanism for when a dependent object is changed.  It only
        makes sense to use this option when this command depends on some
        other object; it is useful for triggering an action:

View on GitHub (pinned to e227c27540)

Solutions

  1. Pass a numeric literal: `try_sleep => 0.5` (or a clean string '0.5').
  2. Convert in the manifest: `try_sleep => Float($raw)` for numeric strings.
  3. Fix the Hiera source to store numbers without units or comma decimals.
  4. Note the regex alone accepts junk like '1..5' — Float() then raises a separate error, so keep values well-formed.

Example fix

// before
exec { 'retry_thing':
  command   => '/opt/app/job.sh',
  try_sleep => '0.5s',
}

// after
exec { 'retry_thing':
  command   => '/opt/app/job.sh',
  try_sleep => 0.5,
}
Defensive patterns

Strategy: validation

Validate before calling

// Puppet
unless $try_sleep =~ Numeric or ($try_sleep =~ String and $try_sleep =~ Pattern[/\A[-\d.]+\z/]) {
  fail("exec: try_sleep must be a number, got '${try_sleep}'")
}

Type guard

def valid_try_sleep?(v)
  parsed = v.is_a?(Numeric) ? v : (Float(v) if v.is_a?(String) && v.match?(/\A[-\d.]+\z/)) rescue nil
  !parsed.nil? && parsed >= 0
end

Prevention

When it happens

Trigger: `try_sleep => 'five'`, '1,5' (comma decimal), '0.5s' or '500ms' (units), ' 10' or "10\n" from templates. Digit/period/minus strings like '3' and '-2.5' parse fine, so only malformed numeric strings trip this.

Common situations: European locale comma decimals in shared Hiera data; appending units because try_sleep is Float seconds; template whitespace; confusing try_sleep (Float seconds) with tries (Integer).

Related errors


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