{"record":{"id":"7e199f5eae2f2487","repo":"puppetlabs/puppet","slug":"label-has-no-value","errorCode":null,"errorMessage":"#{label} has no value","messagePattern":"#(.+?) has no value","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/pops/types/p_object_type.rb","lineNumber":370,"sourceCode":"    # @return [Booelan] true if the given value equals the default value for this attribute\n    def default_value?(value)\n      @value == value\n    end\n\n    # @return [Boolean] `true` if a value has been defined for this attribute.\n    def value?\n      @value != :undef\n    end\n\n    # Returns the value of this attribute, or raises an error if no value has been defined. Raising an error\n    # is necessary since a defined value may be `nil`.\n    #\n    # @return [Object] the value that has been defined for this attribute.\n    # @raise [Puppet::Error] if no value has been defined\n    # @api public\n    def value\n      # An error must be raised here since `nil` is a valid value and it would be bad to leak the :undef symbol\n      raise Puppet::Error, \"#{label} has no value\" if @value == :undef\n\n      @value\n    end\n\n    # @api private\n    def self.feature_type\n      'attribute'\n    end\n  end\n\n  class PTypeParameter < PAttribute\n    # @return [Hash{String=>Object}] the hash\n    # @api private\n    def _pcore_init_hash\n      hash = super\n      hash[KEY_TYPE] = hash[KEY_TYPE].type\n      hash.delete(KEY_VALUE) if hash.include?(KEY_VALUE) && hash[KEY_VALUE].nil?\n      hash","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/pops/types/p_object_type.rb#L352-L388","documentation":"PAttribute tracks 'no value' with the internal sentinel :undef because nil is a perfectly valid default value. Calling #value on an attribute that has no default therefore cannot return nil; it raises Puppet::Error. The companion predicate #value? (true unless the value is :undef) exists exactly for this check.","triggerScenarios":"Ruby code that walks an Object type's attributes and calls attr.value unconditionally — e.g. tooling that builds documentation, forms, or serializers from type definitions, encountering attributes of kind 'derived'/'given_or_derived' or plain attributes without defaults.","commonSituations":"Generic reflection over Puppet::Pops::Types::PObjectType attributes that assumes every attribute has a default; mixing up #value (raises when absent) with #value? (predicate).","solutions":["Guard the access: attr.value? ? attr.value : nil (or your own sentinel/behavior).","Filter first: type.attributes.values.select(&:value?).each { |a| use a.value }.","Never test @value/nil yourself — the :undef sentinel must not leak into user code."],"exampleFix":"# before\ntype.attributes.each_value { |a| defaults[a.name] = a.value }\n\n# after\ntype.attributes.each_value { |a| defaults[a.name] = a.value if a.value? }","handlingStrategy":"type-guard","validationCode":"# Ruby — always pair the predicate with the accessor\nvalue = attr.value? ? attr.value : my_default","typeGuard":"def attribute_value_or(attr, fallback = nil)\n  attr.value? ? attr.value : fallback\nend","tryCatchPattern":"begin\n  a.value\nrescue Puppet::Error\n  nil # attribute has no default; handle accordingly\nend","preventionTips":["Standardize on the value?/value pair in reflection code over attributes.","Remember nil is a legitimate default — absence is signaled by value? == false, never by nil."],"tags":["puppet","object-type","reflection","default-value","ruby-api"],"backgroundTag":"accessing-missing-attribute-value","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}