puppetlabs/puppet · error · ArgumentError

Parameter 'type' must be a String reference to a Puppet Data

Error message

Parameter 'type' must be a String reference to a Puppet Data Type. Got %{type_class}

What it means

The type argument to param-style declarations must be a String reference to a Puppet data type, or an already constructed PAnyType instance. A Ruby class, Symbol, or any other object fails the check in internal_param and raises this ArgumentError at definition time.

Source

Thrown at lib/puppet/functions.rb:552

    def internal_param(type, name, repeat = false)
      raise ArgumentError, _('Parameters cannot be added after a block parameter') unless @block_type.nil?
      raise ArgumentError, _('Parameters cannot be added after a repeated parameter') if @max == :default

      if name.is_a?(String)
        raise ArgumentError, _("Parameter name argument must be a Symbol. Got %{name_class}") % { name_class: name.class }
      end

      if type.is_a?(String) || type.is_a?(Puppet::Pops::Types::PAnyType)
        @types << type
        @names << name
        # mark what should be picked for this position when dispatching
        if repeat
          @weaving << -@names.size()
        else
          @weaving << @names.size() - 1
        end
      else
        raise ArgumentError, _("Parameter 'type' must be a String reference to a Puppet Data Type. Got %{type_class}") % { type_class: type.class }
      end
    end

    # @api private
    def dispatch(meth_name, argument_mismatch_handler, &block)
      # an array of either an index into names/types, or an array with
      # injection information [type, name, injection_name] used when the call
      # is being made to weave injections into the given arguments.
      #
      @types = []
      @names = []
      @weaving = []
      @injections = []
      @min = 0
      @max = 0
      @block_type = nil
      @block_name = nil
      @return_type = nil

View on GitHub (pinned to e227c27540)

Solutions

  1. Quote the type reference: param 'Integer', :count.
  2. Or pass a constructed type, for example Puppet::Pops::Types::TypeFactory.integer.
  3. Prefer the quoted-string form for readability; keep Ruby constants out of the type position.

Example fix

# before
 param Integer, :count
 param :count

# after
 param 'Integer', :count
 param Puppet::Pops::Types::TypeFactory.integer, :count
Defensive patterns

Strategy: type-guard

Type guard

type_arg_guard = ->(t) { t.is_a?(String) || t.is_a?(Puppet::Pops::Types::PAnyType) }
raise ArgumentError, 'type must be a String data-type reference' unless type_arg_guard.call('Integer')

Prevention

When it happens

Trigger: param Integer, :count (a Ruby Class), or param :x (a Symbol). Only param 'Integer', :count or a Puppet::Pops::Types object is accepted.

Common situations: Ruby muscle memory (Integer looks natural after writing plain Ruby); refactors that replace quoted strings with constants; leftover Symbols from name-only lines.

Related errors


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