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.
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)
Solutions
- Rename the Ruby method so it equals the function name exactly (underscored form).
- Or add an explicit dispatch :your_method do ... end block that names the real method. This also lets you declare parameter types.
- 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
- Write an explicit dispatch :method block in every function; never rely on the implicit default.
- Keep the implementing method name identical to the function name (underscored form).
- Add one invoking spec per function so a missing dispatcher fails in CI.
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
- Function Load Error for function '%{function_name}': %{messa
- Functions must be based on Puppet::Pops::Functions::Function
- A required parameter cannot be added after an optional param
- A required repeated parameter cannot be added after an optio
- block_param accepts max 2 arguments (type, name), got %{size
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/b27310332dd86523.
Report an issue: GitHub.