puppetlabs/puppet · error · ArgumentError

IllegalStruct member key type. Expected NotUndef, Optional,

Error message

IllegalStruct member key type. Expected NotUndef, Optional, String, or Enum. Got: #{key_type.class.name}

What it means

Error "IllegalStruct member key type. Expected NotUndef, Optional, String, or Enum. Got: #{key_type.class.name}" thrown in puppetlabs/puppet.

Source

Thrown at lib/puppet/pops/types/type_factory.rb:201

        key_type = string(key_type)
        # Must make key optional if the value can be Undef
        key_type = optional(key_type) if tc.assignable?(value_type, PUndefType::DEFAULT)
      else
        # assert that the key type is one of String[1], NotUndef[String[1]] and Optional[String[1]]
        case key_type
        when PNotUndefType
          # We can loose the NotUndef wrapper here since String[1] isn't optional anyway
          key_type = key_type.type
          s = key_type
        when POptionalType
          s = key_type.optional_type
        when PStringType
          s = key_type
        when PEnumType
          s = key_type.values.size == 1 ? PStringType.new(key_type.values[0]) : nil
        else
          raise ArgumentError, "Illegal Struct member key type. Expected NotUndef, Optional, String, or Enum. Got: #{key_type.class.name}"
        end
        unless s.is_a?(PStringType) && !s.value.nil?
          raise ArgumentError, "Unable to extract a non-empty literal string from Struct member key type #{tc.string(key_type)}"
        end
      end
      PStructElement.new(key_type, value_type)
    end
    PStructType.new(elements)
  end

  # Produces an `Object` type from the given _hash_ that represents the features of the object
  #
  # @param hash [{String=>Object}] the hash of feature groups
  # @return [PObjectType] the created type
  #
  def self.object(hash = nil, loader = nil)
    hash.nil? || hash.empty? ? PObjectType::DEFAULT : PObjectType.new(hash, loader)
  end

View on GitHub (pinned to e227c27540)

When it happens

Trigger: Thrown at lib/puppet/pops/types/type_factory.rb:201 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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