puppetlabs/puppet · error · ArgumentError

Function Creation Error, cannot create a default dispatcher…

Error message

Function Creation Error, cannot create a default dispatcher for function '%{func_name}', no method with this name found

What it means

When a create_function block declares no explicit dispatch entries, Puppet builds a default dispatcher from an instance method whose name equals the function name. This ArgumentError means the created class has no method with that name. The usual cause is a method renamed away from the function name, or an implementation method whose spelling does not match the underscored function name.

Solutions

  1. Rename the Ruby method so it equals the function name exactly (underscored form).
  2. Or add an explicit dispatch :your_method do ... end block that names the real method. This also lets you declare parameter types.
  3. Add a minimal unit test that calls each function once, so a missing dispatcher fails in CI instead of at catalog compile.

Example fix

# before: method name does not match function name, no dispatch
Puppet::Functions.create_function(:shout) do
  def speak(s); s.upcase; end
end

# after: explicit dispatch names the implementation method
Puppet::Functions.create_function(:shout) do
  dispatch :speak do
    param 'String', :s
  end
  def speak(s); s.upcase; end
end
Defensive patterns

Strategy: validation

Validate before calling

# Spec-time check: building and calling the function exercises the default dispatcher
it 'defines a dispatchable method' do
  expect { subject.invoke('x') }.not_to raise_error
end

Prevention

When it happens

Trigger: Puppet::Functions.create_function(:camel_case) with an implementing method def camelcase (name mismatch), or a block that defines only helper methods and no entry method, with no dispatch block anywhere.

Common situations: Renaming a function without renaming the Ruby method; snake_case conversions (function names are underscored by convention, and the method must match exactly); refactors that delete the main method but keep helpers.

Related errors


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

Appendix: source

Thrown at lib/puppet/functions.rb:273

    # does not match a given method name in user code.
    #
    if the_class.dispatcher.empty?
      simple_name = func_name.split(/::/)[-1]
      type, names = default_dispatcher(the_class, simple_name)
      last_captures_rest = (type.size_range[1] == Float::INFINITY)
      the_class.dispatcher.add(Puppet::Pops::Functions::Dispatch.new(type, simple_name, names, last_captures_rest))
    end

    # The function class is returned as the result of the create function method
    the_class
  end

  # Creates a default dispatcher configured from a method with the same name as the function
  #
  # @api private
  def self.default_dispatcher(the_class, func_name)
    unless the_class.method_defined?(func_name)
      raise ArgumentError, _("Function Creation Error, cannot create a default dispatcher for function '%{func_name}', no method with this name found") % { func_name: func_name }
    end

    any_signature(*min_max_param(the_class.instance_method(func_name)))
  end

  # @api private
  def self.min_max_param(method)
    result = { :req => 0, :opt => 0, :rest => 0 }
    # count per parameter kind, and get array of names
    names = method.parameters.map { |p| result[p[0]] += 1; p[1].to_s }
    from = result[:req]
    to = result[:rest] > 0 ? :default : from + result[:opt]
    [from, to, names]
  end

  # Construct a signature consisting of Object type, with min, and max, and given names.
  # (there is only one type entry).
  #

View on GitHub (pinned to e227c27540)