{"record":{"id":"09857c90c5d0292b","repo":"puppetlabs/puppet","slug":"struct-element-key-cannot-be-an-empty-string","errorCode":null,"errorMessage":"Struct element key cannot be an empty String","messagePattern":"Struct element key cannot be an empty String","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/type_factory.rb","lineNumber":182,"sourceCode":"  # all structs (i.e. all hashes) or a hash with entries where the key is\n  # either a literal String, an Enum with one entry, or a String representing exactly one value.\n  # The key type may also be wrapped in a NotUndef or an Optional.\n  #\n  # The value can be a ruby class, a String (interpreted as the name of a ruby class) or\n  # a Type.\n  #\n  # @param hash [{String,PAnyType=>PAnyType}] key => value hash\n  # @return [PStructType] the created Struct type\n  #\n  def self.struct(hash = {})\n    tc = @type_calculator\n    elements = hash.map do |key_type, value_type|\n      value_type = type_of(value_type)\n      raise ArgumentError, 'Struct element value_type must be a Type' unless value_type.is_a?(PAnyType)\n\n      # TODO: Should have stricter name rule\n      if key_type.is_a?(String)\n        raise ArgumentError, 'Struct element key cannot be an empty String' if key_type.empty?\n\n        key_type = string(key_type)\n        # Must make key optional if the value can be Undef\n        key_type = optional(key_type) if tc.assignable?(value_type, PUndefType::DEFAULT)\n      else\n        # assert that the key type is one of String[1], NotUndef[String[1]] and Optional[String[1]]\n        case key_type\n        when PNotUndefType\n          # We can loose the NotUndef wrapper here since String[1] isn't optional anyway\n          key_type = key_type.type\n          s = key_type\n        when POptionalType\n          s = key_type.optional_type\n        when PStringType\n          s = key_type\n        when PEnumType\n          s = key_type.values.size == 1 ? PStringType.new(key_type.values[0]) : nil\n        else","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/type_factory.rb#L164-L200","documentation":"Error \"Struct element key cannot be an empty String\" thrown in puppetlabs/puppet.","triggerScenarios":"Thrown at lib/puppet/pops/types/type_factory.rb:182 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}