{"record":{"id":"b27310332dd86523","repo":"puppetlabs/puppet","slug":"function-creation-error-cannot-create-a-default-d","errorCode":null,"errorMessage":"Function Creation Error, cannot create a default dispatcher for function '%{func_name}', no method with this name found","messagePattern":"Function Creation Error, cannot create a default dispatcher for function '%(.+?)', no method with this name found","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/functions.rb","lineNumber":273,"sourceCode":"    # does not match a given method name in user code.\n    #\n    if the_class.dispatcher.empty?\n      simple_name = func_name.split(/::/)[-1]\n      type, names = default_dispatcher(the_class, simple_name)\n      last_captures_rest = (type.size_range[1] == Float::INFINITY)\n      the_class.dispatcher.add(Puppet::Pops::Functions::Dispatch.new(type, simple_name, names, last_captures_rest))\n    end\n\n    # The function class is returned as the result of the create function method\n    the_class\n  end\n\n  # Creates a default dispatcher configured from a method with the same name as the function\n  #\n  # @api private\n  def self.default_dispatcher(the_class, func_name)\n    unless the_class.method_defined?(func_name)\n      raise ArgumentError, _(\"Function Creation Error, cannot create a default dispatcher for function '%{func_name}', no method with this name found\") % { func_name: func_name }\n    end\n\n    any_signature(*min_max_param(the_class.instance_method(func_name)))\n  end\n\n  # @api private\n  def self.min_max_param(method)\n    result = { :req => 0, :opt => 0, :rest => 0 }\n    # count per parameter kind, and get array of names\n    names = method.parameters.map { |p| result[p[0]] += 1; p[1].to_s }\n    from = result[:req]\n    to = result[:rest] > 0 ? :default : from + result[:opt]\n    [from, to, names]\n  end\n\n  # Construct a signature consisting of Object type, with min, and max, and given names.\n  # (there is only one type entry).\n  #","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/functions.rb#L255-L291","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before: method name does not match function name, no dispatch\nPuppet::Functions.create_function(:shout) do\n  def speak(s); s.upcase; end\nend\n\n# after: explicit dispatch names the implementation method\nPuppet::Functions.create_function(:shout) do\n  dispatch :speak do\n    param 'String', :s\n  end\n  def speak(s); s.upcase; end\nend","handlingStrategy":"validation","validationCode":"# Spec-time check: building and calling the function exercises the default dispatcher\nit 'defines a dispatchable method' do\n  expect { subject.invoke('x') }.not_to raise_error\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["puppet","functions","dispatcher","method-missing"],"backgroundTag":"missing-method-definition","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}