puppetlabs/puppet · error · ArgumentError

Struct element key cannot be an empty String

Error message

Struct element key cannot be an empty String

What it means

Error "Struct element key cannot be an empty String" thrown in puppetlabs/puppet.

Source

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

  # all structs (i.e. all hashes) or a hash with entries where the key is
  # either a literal String, an Enum with one entry, or a String representing exactly one value.
  # The key type may also be wrapped in a NotUndef or an Optional.
  #
  # The value can be a ruby class, a String (interpreted as the name of a ruby class) or
  # a Type.
  #
  # @param hash [{String,PAnyType=>PAnyType}] key => value hash
  # @return [PStructType] the created Struct type
  #
  def self.struct(hash = {})
    tc = @type_calculator
    elements = hash.map do |key_type, value_type|
      value_type = type_of(value_type)
      raise ArgumentError, 'Struct element value_type must be a Type' unless value_type.is_a?(PAnyType)

      # TODO: Should have stricter name rule
      if key_type.is_a?(String)
        raise ArgumentError, 'Struct element key cannot be an empty String' if key_type.empty?

        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

View on GitHub (pinned to e227c27540)

When it happens

Trigger: Thrown at lib/puppet/pops/types/type_factory.rb:182 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/09857c90c5d0292b. Report an issue: GitHub.