{"record":{"id":"7c72d1744b8296c6","repo":"puppetlabs/puppet","slug":"the-code-loaded-from-source-ref-does-not-define-7c72d1","errorCode":null,"errorMessage":"The code loaded from %{source_ref} does not define the function '%{type_name}' - no function found.","messagePattern":"The code loaded from %(.+?) does not define the function '%(.+?)' - no function found\\.","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/loader/puppet_function_instantiator.rb","lineNumber":36,"sourceCode":"  #\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 }\n    end\n\n    # Adapt the function definition with loader - this is used from logic contained in it body to find the\n    # loader to use when making calls to the new function API. Such logic have a hard time finding the closure (where\n    # the loader is known - hence this mechanism\n    private_loader = loader.private_loader\n    Adapters::LoaderAdapter.adapt(the_function_definition).loader_name = private_loader.loader_name\n\n    # Cannot bind loaded functions to global scope, that must be done without binding that scope as","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/loader/puppet_function_instantiator.rb#L18-L54","documentation":"Error \"The code loaded from %{source_ref} does not define the function '%{type_name}' - no function found.\" thrown in puppetlabs/puppet.","triggerScenarios":"Thrown at lib/puppet/pops/loader/puppet_function_instantiator.rb:36 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"}