puppetlabs/puppet · error · ArgumentError

default value for %{name} is a %{class_name}, not a proc

Error message

default value for %{name} is a %{class_name}, not a proc

What it means

Puppet::Interface::Option#default= only accepts a Proc, because the default is evaluated lazily via `@default.call` in Option#default (lib/puppet/interface/option.rb:133). Assigning any non-callable object (String, Symbol, Method) raises ArgumentError naming the actual class. The Faces DSL `default_to { ... }` always wraps its block, so this is hit only through direct Option manipulation.

Source

Thrown at lib/puppet/interface/option.rb:133

    !!@optional_argument
  end

  def required?
    !!@required
  end

  def has_default?
    !!@default
  end

  def default=(proc)
    if required
      raise ArgumentError, _("%{name} can't be optional and have a default value") % { name: self }
    end

    unless proc.is_a? Proc
      # TRANSLATORS 'proc' is a Ruby block of code
      raise ArgumentError, _("default value for %{name} is a %{class_name}, not a proc") %
                           { name: self, class_name: proc.class.name.inspect }
    end
    @default = proc
  end

  def default
    @default and @default.call
  end

  attr_reader :parent, :name, :aliases, :optparse, :required

  def required=(value)
    if has_default?
      raise ArgumentError, _("%{name} can't be optional and have a default value") % { name: self }
    end

    @required = value
  end

View on GitHub (pinned to e227c27540)

Solutions

  1. Wrap the value in a Proc: `opt.default = -> { 'production' }`
  2. For Method objects use `opt.default = method(:default_env).to_proc`, which does return a Proc
  3. Prefer the DSL `default_to { 'production' }`, which enforces the block for you

Example fix

# before
opt.default = "production"

# after
opt.default = -> { "production" }
Defensive patterns

Strategy: type-guard

Type guard

# Ruby — narrow to Proc before assigning
def proc!(value, what)
  return value if value.is_a?(Proc)
  raise ArgumentError, "#{what} must be a Proc, got #{value.class}"
end

opt.default = proc!(candidate, 'default')

Prevention

When it happens

Trigger: `opt.default = "production"` (String); `opt.default = method(:default_env)` — a Method object is not a Proc and fails `proc.is_a? Proc`; assigning a configuration value read from YAML/JSON.

Common situations: Migrating static hash-of-defaults code to Option objects; choosing `method(:sym)` for readability; JSON-driven option configuration supplying scalar defaults.

Related errors


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