puppetlabs/puppet · error · ArgumentError

The code loaded from

Error message

The code loaded from %{source_ref} does not define the function '%{func_name}' - it is empty.

What it means

PuppetFunctionInstantiator parsed the loaded .pp source but found zero definitions where exactly one function definition was expected (the file is empty or has no function).

Solutions

  1. Add the expected function definition to the loaded Puppet source file
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at lib/puppet/pops/loader/puppet_function_instantiator.rb:27 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at lib/puppet/pops/loader/puppet_function_instantiator.rb:27

  # Produces an instance of the Function class with the given typed_name, or fails with an error if the
  # given puppet source does not produce this instance when evaluated.
  #
  # @param loader [Loader] The loader the function is associated with
  # @param typed_name [TypedName] the type / name of the function to load
  # @param source_ref [URI, String] a reference to the source / origin of the puppet code to evaluate
  # @param pp_code_string [String] puppet code in a string
  #
  # @return [Functions::Function] - an instantiated function with global scope closure associated with the given loader
  #
  def self.create(loader, typed_name, source_ref, pp_code_string)
    parser = Parser::EvaluatingParser.new()

    # parse and validate
    result = parser.parse_string(pp_code_string, source_ref)
    # Only one function is allowed (and no other definitions)
    case result.definitions.size
    when 0
      raise ArgumentError, _("The code loaded from %{source_ref} does not define the function '%{func_name}' - it is empty.") % { source_ref: source_ref, func_name: typed_name.name }
    when 1
      # ok
    else
      raise ArgumentError, _("The code loaded from %{source_ref} must contain only the function '%{type_name}' - it has additional definitions.") % { source_ref: source_ref, type_name: typed_name.name }
    end
    the_function_definition = result.definitions[0]

    unless the_function_definition.is_a?(Model::FunctionDefinition)
      raise ArgumentError, _("The code loaded from %{source_ref} does not define the function '%{type_name}' - no function found.") % { source_ref: source_ref, type_name: typed_name.name }
    end

    unless the_function_definition.name == typed_name.name
      expected = typed_name.name
      actual = the_function_definition.name
      raise ArgumentError, _("The code loaded from %{source_ref} produced function with the wrong name, expected %{expected}, actual %{actual}") % { source_ref: source_ref, expected: expected, actual: actual }
    end
    unless result.body == the_function_definition
      raise ArgumentError, _("The code loaded from %{source} contains additional logic - can only contain the function %{name}") % { source: source_ref, name: typed_name.name }

View on GitHub (pinned to e227c27540)