puppetlabs/puppet · error · ArgumentError

Tries must be an integer >= 1

Error message

Tries must be an integer >= 1

What it means

After munging, the exec type enforces `raise ... if value < 1`, so any syntactically valid integer of zero or below raises ArgumentError 'Tries must be an integer >= 1'. At least one execution attempt must happen, so 0 or negative retry counts are meaningless.

Source

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

      defaultto 300
    end

    newparam(:tries) do
      desc "The number of times execution of the command should be tried.
        This many attempts will be made to execute the command until an
        acceptable return code is returned. Note that the timeout parameter
        applies to each try rather than to the complete set of tries."

      munge do |value|
        if value.is_a?(String)
          unless value =~ /^\d+$/
            raise ArgumentError, _("Tries must be an integer")
          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

View on GitHub (pinned to e227c27540)

Solutions

  1. Use 1 or higher; 1 is the default and means a single attempt.
  2. If the intent is 'no retries', omit `tries` entirely instead of using 0.
  3. Clamp computed values: `tries => max(1, $computed)`.
  4. Fail early in the manifest: `assert_type(Integer[1, default], $tries)`.

Example fix

// before
exec { 'retry_thing':
  command => '/opt/app/job.sh',
  tries   => 0,
}

// after: omit tries (default 1) or set >= 1
exec { 'retry_thing':
  command => '/opt/app/job.sh',
  tries   => 3,
}
Defensive patterns

Strategy: validation

Validate before calling

// Puppet
unless $tries =~ Integer and $tries >= 1 {
  fail("exec: tries must be >= 1, got '${tries}'")
}

Type guard

def positive_tries?(v)
  n = v.is_a?(Integer) ? v : (v.to_i if v.is_a?(String) && v.match?(/\A\d+\z/))
  !n.nil? && n >= 1
end

Prevention

When it happens

Trigger: `tries => 0`, `tries => -2`, or strings '0'/'00' (digit-only, so they pass the regex, then fail the >= 1 check); computed values from Hiera or arithmetic that evaluate to 0 on some nodes.

Common situations: Using 0 to mean 'disable retrying' (it actually requests zero attempts); computing tries as a difference without a floor; environment-specific Hiera overrides setting 0 in dev tiers.

Related errors


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