{"record":{"id":"54c5ef594f29d082","repo":"puppetlabs/puppet","slug":"argument-to-return-type-must-be-a-string-referen","errorCode":null,"errorMessage":"Argument to 'return_type' must be a String reference to a Puppet Data Type. Got %{type_class}","messagePattern":"Argument to 'return_type' must be a String reference to a Puppet Data Type\\. Got %(.+?)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/functions.rb","lineNumber":525,"sourceCode":"\n    # Defines one optional block parameter that may appear last. If type or name is missing the\n    # defaults are \"any callable\", and the name is \"block\". The implementor of the dispatch target\n    # must use block = nil when it is optional (or an error is raised when the call is made).\n    #\n    # @api public\n    def optional_block_param(*type_and_name)\n      # same as required, only wrap the result in an optional type\n      required_block_param(*type_and_name)\n      @block_type = Puppet::Pops::Types::TypeFactory.optional(@block_type)\n    end\n\n    # Defines the return type. Defaults to 'Any'\n    # @param [String] type a reference to a Puppet Data Type\n    #\n    # @api public\n    def return_type(type)\n      unless type.is_a?(String) || type.is_a?(Puppet::Pops::Types::PAnyType)\n        raise ArgumentError, _(\"Argument to 'return_type' must be a String reference to a Puppet Data Type. Got %{type_class}\") % { type_class: type.class }\n      end\n\n      @return_type = type\n    end\n\n    private\n\n    # @api private\n    def internal_param(type, name, repeat = false)\n      raise ArgumentError, _('Parameters cannot be added after a block parameter') unless @block_type.nil?\n      raise ArgumentError, _('Parameters cannot be added after a repeated parameter') if @max == :default\n\n      if name.is_a?(String)\n        raise ArgumentError, _(\"Parameter name argument must be a Symbol. Got %{name_class}\") % { name_class: name.class }\n      end\n\n      if type.is_a?(String) || type.is_a?(Puppet::Pops::Types::PAnyType)\n        @types << type","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/functions.rb#L507-L543","documentation":"return_type declares what a function returns. Its argument must be a String reference to a Puppet data type (parsed later) or an already-built PAnyType instance. Anything else, such as a Ruby class or a Symbol, raises this ArgumentError at definition time.","triggerScenarios":"return_type Integer (a Ruby Class) or return_type :String (a Symbol) inside a create_function block. Only return_type 'Integer' or a Puppet::Pops::Types instance is accepted.","commonSituations":"Muscle memory from Ruby method signatures; refactoring from param-style strings to Ruby constants and over-applying it to return_type.","solutions":["Quote the type: return_type 'String' or return_type 'Optional[Array[Integer]]'.","Or pass a constructed type object, for example Puppet::Pops::Types::TypeFactory.string.","Check for stray colons after refactors; Symbols fail the check."],"exampleFix":"# before\n return_type Integer\n return_type :String\n\n# after\n return_type 'Integer'\n return_type 'Optional[Array[Integer]]'","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"return_type_guard = ->(t) { t.is_a?(String) || t.is_a?(Puppet::Pops::Types::PAnyType) }\nraise ArgumentError, 'quote return types: \"String\"' unless return_type_guard.call('String')","tryCatchPattern":null,"preventionTips":["Always quote return types: return_type 'String'.","Pass PAnyType instances from TypeFactory when types are built programmatically.","Reject Symbols and Ruby classes in the return-type position during review."],"tags":["puppet","functions","return-type","type-validation","dsl"],"backgroundTag":"invalid-return-type","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}