puppetlabs/puppet · error · ArgumentError

Expected a type alias assignment on the form 'AliasType = T'

Error message

Expected a type alias assignment on the form 'AliasType = T', got '%{assignment_string}'.
Called from <%{ruby_file_location}>

What it means

After local_types parses a 'type ...' string successfully, the result body must be a Puppet::Pops::Model::TypeAlias node, that is, a real assignment 'AliasName = T'. A string that parses as something else (a bare expression, a function call) raises this ArgumentError with the Ruby location of the type call.

Source

Thrown at lib/puppet/functions.rb:644

      # but strips off the rest of the internal "where" as it is not meaningful to user.
      #
      rb_location = caller(1, 1).first
      begin
        result = parser.parse_string("type #{assignment_string}", nil)
      rescue StandardError => e
        rb_location = rb_location.gsub(/:in.*$/, '')
        # Create a meaningful location for parse errors - show both what went wrong with the parsing
        # and in which ruby file it was found.
        raise ArgumentError, _("Parsing of 'type \"%{assignment_string}\"' failed with message: <%{message}>.\n" \
                               "Called from <%{ruby_file_location}>") % {
                                 assignment_string: assignment_string,
                                 message: e.message,
                                 ruby_file_location: rb_location
                               }
      end
      unless result.body.is_a?(Puppet::Pops::Model::TypeAlias)
        rb_location = rb_location.gsub(/:in.*$/, '')
        raise ArgumentError, _("Expected a type alias assignment on the form 'AliasType = T', got '%{assignment_string}'.\n" \
                               "Called from <%{ruby_file_location}>") % {
                                 assignment_string: assignment_string,
                                 ruby_file_location: rb_location
                               }
      end
      @local_types << result.body
    end
  end

  # @note WARNING: This style of creating functions is not public. It is a system
  #   under development that will be used for creating "system" functions.
  #
  # This is a private, internal, system for creating functions. It supports
  # everything that the public function definition system supports as well as a
  # few extra features such as injection of well known parameters.
  #
  # @api private
  class InternalFunction < Function

View on GitHub (pinned to e227c27540)

Solutions

  1. Write a full assignment: 'AliasName = Type', for example 'MyList = Array[String]'.
  2. Check that exactly one '=' separates the new name from the existing type.
  3. Reuse the standalone parser check to confirm the body class: result.body.is_a?(Puppet::Pops::Model::TypeAlias).

Example fix

# before: parses, but is not an alias assignment
 local_types { type 'MyList' }

# after: correct 'AliasType = T' form
 local_types { type 'MyList = Array[String]' }
Defensive patterns

Strategy: validation

Validate before calling

# Assert each alias string yields a real TypeAlias node
result = Puppet::Pops::Parser::Parser.new.parse_string('type MyList = Array[String]')
raise 'not an alias assignment' unless result.body.is_a?(Puppet::Pops::Model::TypeAlias)

Prevention

When it happens

Trigger: local_types { type 'MyList' } (no '=' at all, parses as a bare type reference), or type 'MyList.size' style expressions. The parse succeeds but the body is not a TypeAlias.

Common situations: Forgetting the '=' in the alias assignment; writing a type expression where a definition was intended; shorthand habits from Puppet language manifests carried into the Ruby DSL.

Related errors


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