puppetlabs/puppet · error · ArgumentError

Parameter name argument must be a Symbol. Got %{name_class}

Error message

Parameter name argument must be a Symbol. Got %{name_class}

What it means

In internal_param, the name argument for param/optional_param/repeated params must be a Symbol. A String name fails the is_a?(String) check and raises this ArgumentError with the offending class. The name is used for error messages and dispatch weaving, and Symbols keep it unambiguous with type strings.

Source

Thrown at lib/puppet/functions.rb:539

    #
    # @api public
    def return_type(type)
      unless type.is_a?(String) || type.is_a?(Puppet::Pops::Types::PAnyType)
        raise ArgumentError, _("Argument to 'return_type' must be a String reference to a Puppet Data Type. Got %{type_class}") % { type_class: type.class }
      end

      @return_type = type
    end

    private

    # @api private
    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)

View on GitHub (pinned to e227c27540)

Solutions

  1. Write the name with a leading colon: param 'String', :name.
  2. In generators, call to_sym on the name before passing it.
  3. Adopt a style rule: type on the left quoted, name on the right as a Symbol.

Example fix

# before
 param 'String', 'name'

# after
 param 'String', :name
Defensive patterns

Strategy: type-guard

Validate before calling

# For generated signatures: coerce before building the dispatch
names = names.map(&:to_sym)

Type guard

symbol_name = ->(n) { n.is_a?(Symbol) }
raise ArgumentError, 'names must be Symbols' unless %i[x y].all? { |n| symbol_name.call(n) }

Prevention

When it happens

Trigger: param 'String', 'name' (both arguments quoted), or a name computed at runtime that happens to be a String instead of a Symbol.

Common situations: Quoting both arguments by habit; converting signatures from data (for example from a YAML-driven generator) that yields strings for names.

Related errors


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