{"record":{"id":"faeda9c2dffcff3d","repo":"puppetlabs/puppet","slug":"tries-must-be-an-integer","errorCode":null,"errorMessage":"Tries must be an integer","messagePattern":"Tries must be an integer","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/type/exec.rb","lineNumber":355,"sourceCode":"        rescue ArgumentError => e\n          raise ArgumentError, _(\"The timeout must be a number.\"), e.backtrace\n        end\n        [value, 0.0].max\n      end\n\n      defaultto 300\n    end\n\n    newparam(:tries) do\n      desc \"The number of times execution of the command should be tried.\n        This many attempts will be made to execute the command until an\n        acceptable return code is returned. Note that the timeout parameter\n        applies to each try rather than to the complete set of tries.\"\n\n      munge do |value|\n        if value.is_a?(String)\n          unless value =~ /^\\d+$/\n            raise ArgumentError, _(\"Tries must be an integer\")\n          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.]+$/","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/type/exec.rb#L337-L373","documentation":"The Puppet `exec` type munges its `tries` parameter: when the value is a String it must match the digit-only regex /^\\d+$/ before Integer() converts it. Any string containing letters, a sign, a decimal point, a comma, or whitespace raises this ArgumentError while the resource is being built or the catalog compiled.","triggerScenarios":"Declaring `exec { 'x': command => '...', tries => 'abc' }`; passing '1.5' or '2.0' (the '.' fails /^\\d+$/); values like '-1', '+3', ' 3', '1,000', '0x10'; values interpolated from ERB/EPP templates or Hiera that arrive as \"3\\n\". Bare Integers and digit-only strings pass.","commonSituations":"Hiera/YAML values stored as formatted strings; template interpolation appending newlines or spaces; attempts to express fractional retry counts; quoting habits from shell scripts carrying stray characters into the manifest.","solutions":["Set tries to a plain Integer: `tries => 3` (or a digit-only string such as '3').","If the value comes from Hiera or a template, normalize before use: `tries => Integer($raw)`.","Strip whitespace from strings: `tries => regsubst($raw, '\\s', '', 'G')`.","Catch it early with `puppet parser validate` or catalog compilation in CI."],"exampleFix":"// before\nexec { 'migrate':\n  command => '/opt/app/migrate.sh',\n  tries   => '3.0',   // '.' fails /^\\d+$/\n}\n\n// after\nexec { 'migrate':\n  command => '/opt/app/migrate.sh',\n  tries   => 3,\n}","handlingStrategy":"validation","validationCode":"// Puppet, before declaring the exec\nunless $tries =~ Integer or ($tries =~ String and $tries =~ Pattern[/\\A\\d+\\z/]) {\n  fail(\"exec: tries must be an integer >= 1 or digit-only string, got '${tries}'\")\n}","typeGuard":"def valid_exec_tries?(v)\n  v.is_a?(Integer) ? v >= 1 : v.is_a?(String) && v.match?(/\\A\\d+\\z/) && v.to_i >= 1\nend","tryCatchPattern":"When building resources in Ruby (Puppet::Type::Exec.new), wrap creation in begin/rescue ArgumentError and re-raise with the resource title for context; in manifests the error surfaces at compile time, so catch it with `puppet parser validate` in CI rather than at runtime.","preventionTips":["Always write tries as a bare integer (tries => 3).","Normalize Hiera/template values with Integer() before passing them.","Strip whitespace from interpolated strings (regsubst($v, '\\s', '', 'G')).","Run puppet parser validate / puppet-lint in CI to catch munge errors pre-deploy."],"tags":["puppet","exec","tries","parameter-validation","munge"],"backgroundTag":"invalid-parameter-value","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}