puppetlabs/puppet · error · ArgumentError
try_sleep cannot be a negative number
Error message
try_sleep cannot be a negative number
What it means
After parsing try_sleep, the munge block rejects values below zero with 'try_sleep cannot be a negative number'. A negative sleep interval between retries is meaningless, so Numeric values or strings like '-1' / '-0.25' that munge below 0 raise ArgumentError.
Source
Thrown at lib/puppet/type/exec.rb:379
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:
# Pull down the main aliases file
file { '/etc/aliases':
source => 'puppet://server/module/aliases',
}View on GitHub (pinned to e227c27540)
Solutions
- Use 0 (the default) or a positive value; omit try_sleep when no delay is wanted.
- Clamp computed values: `try_sleep => max(0, Float($raw))`.
- Fix the Hiera/YAML source that supplies the negative number.
Example fix
// before
exec { 'retry_thing':
command => '/opt/app/job.sh',
try_sleep => -1,
}
// after: default is 0; use a positive delay
exec { 'retry_thing':
command => '/opt/app/job.sh',
try_sleep => 1,
} Defensive patterns
Strategy: validation
Validate before calling
// Puppet
$ts = $try_sleep
unless $ts =~ Numeric and $ts >= 0 {
fail("exec: try_sleep cannot be negative, got '${ts}'")
} Type guard
def nonnegative_sleep?(v) n = v.is_a?(Numeric) ? v : (Float(v) if v.is_a?(String) && v.match?(/\A[-\d.]+\z/)) rescue nil !n.nil? && n >= 0 end
Prevention
- Omit try_sleep when no delay is wanted (default 0).
- Clamp computed values: max(0, Float($raw)).
- Review shared Hiera data for stray minus signs.
When it happens
Trigger: `try_sleep => -1` or `try_sleep => '-0.25'`; Hiera values carrying a leading minus; sign errors when computing the sleep from another variable or lookup.
Common situations: Copy-paste from tries-style configs; trying to express 'no delay' — the default is already 0, so omit the parameter; negative values sneaking in through computed data.
Related errors
- Tries must be an integer >= 1
- try_sleep must be a number
- Command must be a String or Array<String>, got value of clas
- Invalid environment setting '%{value}'
- The umask specification is invalid: %{value}
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/fcd7e15bd54d4a78.
Report an issue: GitHub.