{"record":{"id":"4c8fd5e3176c8aff","repo":"puppetlabs/puppet","slug":"try-sleep-must-be-a-number","errorCode":null,"errorMessage":"try_sleep must be a number","messagePattern":"try_sleep must be a number","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/type/exec.rb","lineNumber":374,"sourceCode":"          end\n\n          value = Integer(value)\n        end\n        raise ArgumentError, _(\"Tries must be an integer >= 1\") if value < 1\n\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:","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/type/exec.rb#L356-L392","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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).","solutions":["Pass a numeric literal: `try_sleep => 0.5` (or a clean string '0.5').","Convert in the manifest: `try_sleep => Float($raw)` for numeric strings.","Fix the Hiera source to store numbers without units or comma decimals.","Note the regex alone accepts junk like '1..5' — Float() then raises a separate error, so keep values well-formed."],"exampleFix":"// before\nexec { 'retry_thing':\n  command   => '/opt/app/job.sh',\n  try_sleep => '0.5s',\n}\n\n// after\nexec { 'retry_thing':\n  command   => '/opt/app/job.sh',\n  try_sleep => 0.5,\n}","handlingStrategy":"validation","validationCode":"// Puppet\nunless $try_sleep =~ Numeric or ($try_sleep =~ String and $try_sleep =~ Pattern[/\\A[-\\d.]+\\z/]) {\n  fail(\"exec: try_sleep must be a number, got '${try_sleep}'\")\n}","typeGuard":"def valid_try_sleep?(v)\n  parsed = v.is_a?(Numeric) ? v : (Float(v) if v.is_a?(String) && v.match?(/\\A[-\\d.]+\\z/)) rescue nil\n  !parsed.nil? && parsed >= 0\nend","tryCatchPattern":null,"preventionTips":["Store try_sleep as a YAML number, not a string.","Never append units ('ms', 's') — the value is Float seconds.","Watch locale comma decimals in shared data.","A bare numeric literal in the manifest avoids all string parsing."],"tags":["puppet","exec","try-sleep","parameter-validation","float-parse"],"backgroundTag":"invalid-parameter-value","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}