{"record":{"id":"bb993bbbc09f79d8","repo":"puppetlabs/puppet","slug":"the-code-loaded-from-source-ref-does-not-define","errorCode":null,"errorMessage":"The code loaded from %{source_ref} does not define the function '%{func_name}' - it is empty.","messagePattern":"The code loaded from %(.+?) does not define the function '%(.+?)' - it is empty\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/loader/puppet_function_instantiator.rb","lineNumber":27,"sourceCode":"  # Produces an instance of the Function class with the given typed_name, or fails with an error if the\n  # given puppet source does not produce this instance when evaluated.\n  #\n  # @param loader [Loader] The loader the function is associated with\n  # @param typed_name [TypedName] the type / name of the function to load\n  # @param source_ref [URI, String] a reference to the source / origin of the puppet code to evaluate\n  # @param pp_code_string [String] puppet code in a string\n  #\n  # @return [Functions::Function] - an instantiated function with global scope closure associated with the given loader\n  #\n  def self.create(loader, typed_name, source_ref, pp_code_string)\n    parser = Parser::EvaluatingParser.new()\n\n    # parse and validate\n    result = parser.parse_string(pp_code_string, source_ref)\n    # Only one function is allowed (and no other definitions)\n    case result.definitions.size\n    when 0\n      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 }\n    when 1\n      # ok\n    else\n      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 }\n    end\n    the_function_definition = result.definitions[0]\n\n    unless the_function_definition.is_a?(Model::FunctionDefinition)\n      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 }\n    end\n\n    unless the_function_definition.name == typed_name.name\n      expected = typed_name.name\n      actual = the_function_definition.name\n      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 }\n    end\n    unless result.body == the_function_definition\n      raise ArgumentError, _(\"The code loaded from %{source} contains additional logic - can only contain the function %{name}\") % { source: source_ref, name: typed_name.name }","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/loader/puppet_function_instantiator.rb#L9-L45","documentation":"Error \"The code loaded from %{source_ref} does not define the function '%{func_name}' - it is empty.\" thrown in puppetlabs/puppet.","triggerScenarios":"Thrown at lib/puppet/pops/loader/puppet_function_instantiator.rb:27 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}