{"record":{"id":"0d7e8d9da418c9fe","repo":"puppetlabs/puppet","slug":"label-of-kind-constant-requires-a-value","errorCode":null,"errorMessage":"%{label} of kind 'constant' requires a value","messagePattern":"%(.+?) of kind 'constant' requires a value","errorType":"exception","errorClass":"Puppet::ParseError","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_object_type.rb","lineNumber":320,"sourceCode":"      @kind = init_hash[KEY_KIND]\n      if @kind == ATTRIBUTE_KIND_CONSTANT # final is implied\n        if init_hash.include?(KEY_FINAL) && !@final\n          # TRANSLATOR 'final => false' is puppet syntax and should not be translated\n          raise Puppet::ParseError, _(\"%{label} of kind 'constant' cannot be combined with final => false\") % { label: label }\n        end\n\n        @final = true\n      end\n\n      if init_hash.include?(KEY_VALUE)\n        if @kind == ATTRIBUTE_KIND_DERIVED || @kind == ATTRIBUTE_KIND_GIVEN_OR_DERIVED\n          raise Puppet::ParseError, _(\"%{label} of kind '%{kind}' cannot be combined with an attribute value\") % { label: label, kind: @kind }\n        end\n\n        v = init_hash[KEY_VALUE]\n        @value = v == :default ? v : TypeAsserter.assert_instance_of(nil, type, v) { \"#{label} #{KEY_VALUE}\" }\n      else\n        raise Puppet::ParseError, _(\"%{label} of kind 'constant' requires a value\") % { label: label } if @kind == ATTRIBUTE_KIND_CONSTANT\n\n        @value = :undef # Not to be confused with nil or :default\n      end\n    end\n\n    def callable_type\n      TYPE_ATTRIBUTE_CALLABLE\n    end\n\n    # @api public\n    def eql?(o)\n      super && @kind == o.kind && @value == (o.value? ? o.value : :undef)\n    end\n\n    # Returns the member as a hash suitable as an argument for constructor. Name is excluded\n    # @return [Hash{String=>Object}] the hash\n    # @api private\n    def _pcore_init_hash","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_object_type.rb#L302-L338","documentation":"A kind 'constant' attribute exists to hold a fixed value, so declaring one without a 'value' key is invalid — PAttribute#initialize raises this Puppet::ParseError on the else branch where a valueless attribute would end up as :undef, which is meaningless for a constant.","triggerScenarios":"An attribute hash {'type' => String, 'kind' => 'constant'} with no 'value' entry; commonly the result of setting the kind but forgetting the value, or of a default-stripping transform removing 'value' everywhere.","commonSituations":"Hand-editing type declarations; codegen that emits the kind but serializes the value separately (and omits it); refactors that drop 'value' while switching kinds.","solutions":["Add the required 'value' to the constant attribute: {'kind' => 'constant', 'value' => 'fixed'}.","If no fixed value is intended, drop 'kind' => 'constant' and use a plain (or 'given') attribute.","Add a structural check in codegen: kind 'constant' must always ship with a 'value' key."],"exampleFix":"# before\n{'type' => String, 'kind' => 'constant'}\n\n# after\n{'type' => String, 'kind' => 'constant', 'value' => 'fixed'}","handlingStrategy":"validation","validationCode":"# Ruby — require value on constants before declaration\nif h['kind'] == 'constant' && !h.key?('value')\n  fail(\"constant attribute requires a value\")\nend","typeGuard":"def complete_constant?(h)\n  h['kind'] != 'constant' || h.key?('value')\nend","tryCatchPattern":null,"preventionTips":["Use a schema/lint step for generated type hashes: kind => value presence rules.","Write constants as {'kind' => 'constant', 'value' => ...} atomically."],"tags":["puppet","object-type","attribute-declaration","constant","missing-value"],"backgroundTag":"missing-required-declaration-value","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}