{"record":{"id":"fcd7e15bd54d4a78","repo":"puppetlabs/puppet","slug":"try-sleep-cannot-be-a-negative-number","errorCode":null,"errorMessage":"try_sleep cannot be a negative number","messagePattern":"try_sleep cannot be a negative number","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/type/exec.rb","lineNumber":379,"sourceCode":"\n        value\n      end\n\n      defaultto 1\n    end\n\n    newparam(:try_sleep) do\n      desc \"The time to sleep in seconds between 'tries'.\"\n\n      munge do |value|\n        if value.is_a?(String)\n          unless value =~ /^[-\\d.]+$/\n            raise ArgumentError, _(\"try_sleep must be a number\")\n          end\n\n          value = Float(value)\n        end\n        raise ArgumentError, _(\"try_sleep cannot be a negative number\") if value < 0\n\n        value\n      end\n\n      defaultto 0\n    end\n\n    newcheck(:refreshonly) do\n      desc <<-'EOT'\n        The command should only be run as a\n        refresh mechanism for when a dependent object is changed.  It only\n        makes sense to use this option when this command depends on some\n        other object; it is useful for triggering an action:\n\n            # Pull down the main aliases file\n            file { '/etc/aliases':\n              source => 'puppet://server/module/aliases',\n            }","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/type/exec.rb#L361-L397","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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."],"exampleFix":"// before\nexec { 'retry_thing':\n  command   => '/opt/app/job.sh',\n  try_sleep => -1,\n}\n\n// after: default is 0; use a positive delay\nexec { 'retry_thing':\n  command   => '/opt/app/job.sh',\n  try_sleep => 1,\n}","handlingStrategy":"validation","validationCode":"// Puppet\n$ts = $try_sleep\nunless $ts =~ Numeric and $ts >= 0 {\n  fail(\"exec: try_sleep cannot be negative, got '${ts}'\")\n}","typeGuard":"def nonnegative_sleep?(v)\n  n = v.is_a?(Numeric) ? v : (Float(v) if v.is_a?(String) && v.match?(/\\A[-\\d.]+\\z/)) rescue nil\n  !n.nil? && n >= 0\nend","tryCatchPattern":null,"preventionTips":["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."],"tags":["puppet","exec","try-sleep","range-validation"],"backgroundTag":"invalid-parameter-value","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}