puppetlabs/puppet · error · ArgumentError

%{option} default_to block should not take any arguments

Error message

%{option} default_to block should not take any arguments

What it means

OptionBuilder#default_to requires the block to take no arguments (`block.arity == 0`, lib/puppet/interface/option_builder.rb:105) because Puppet later calls it as a bare `call`. Any declared parameter — a named one or a splat — makes the arity non-zero and fails at face load.

Source

Thrown at lib/puppet/interface/option_builder.rb:105

    @option.required = value
  end

  # Sets a block that will be used to compute the default value for this
  # option. It will be evaluated when the action is invoked. The block
  # should take no arguments.
  # @api public
  # @dsl Faces
  def default_to(&block)
    unless block
      # TRANSLATORS 'default_to' is a method name and should not be translated
      raise ArgumentError, _("%{option} default_to requires a block") % { option: @option }
    end
    if @option.has_default?
      raise ArgumentError, _("%{option} already has a default value") % { option: @option }
    end
    unless block.arity == 0
      # TRANSLATORS 'default_to' is a method name and should not be translated
      raise ArgumentError, _("%{option} default_to block should not take any arguments") % { option: @option }
    end

    @option.default = block
  end
end

View on GitHub (pinned to e227c27540)

Solutions

  1. Drop all block parameters and read state from closures: `default_to { Puppet.settings[:environment] }`
  2. If reusing a parameterized lambda, wrap it: `default_to { compute_default }`
  3. Assert `block.arity == 0` when default blocks come from configuration

Example fix

# before
default_to { |face| face.setting(:environment) }

# after
default_to { Puppet.settings[:environment] }
Defensive patterns

Strategy: validation

Validate before calling

block = proc { Puppet.settings[:environment] }
raise ArgumentError, 'default_to block must take no arguments' unless block.arity == 0
default_to(&block)

Prevention

When it happens

Trigger: `default_to { |face| ... }` (arity 1); `default_to { |*args| ... }` (arity -1); a lambda stored in a variable that takes parameters and is passed with `&`.

Common situations: Assuming the block receives the face or the option; reusing a generic helper block that echoes its arguments.

Related errors


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