{"record":{"id":"0fe999fb9a25b360","repo":"puppetlabs/puppet","slug":"invalid-hasstatus-value-value-inspect","errorCode":null,"errorMessage":"Invalid 'hasstatus' value #{value.inspect}","messagePattern":"Invalid 'hasstatus' value #(.+?)","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/provider/service/init.rb","lineNumber":115,"sourceCode":"        next if name =~ /^\\./\n        next if exclude.include? name\n        next if Puppet::FileSystem.directory?(fullpath)\n        next unless Puppet::FileSystem.executable?(fullpath)\n        next unless is_init?(fullpath)\n\n        instances << new(:name => name, :path => path, :hasstatus => true)\n      end\n    end\n    instances\n  end\n\n  # Mark that our init script supports 'status' commands.\n  def hasstatus=(value)\n    case value\n    when true, \"true\"; @parameters[:hasstatus] = true\n    when false, \"false\"; @parameters[:hasstatus] = false\n    else\n      raise Puppet::Error, \"Invalid 'hasstatus' value #{value.inspect}\"\n    end\n  end\n\n  # Where is our init script?\n  def initscript\n    @initscript ||= search(@resource[:name])\n  end\n\n  def paths\n    @paths ||= @resource[:path].find_all do |path|\n      if Puppet::FileSystem.directory?(path)\n        true\n      else\n        if Puppet::FileSystem.exist?(path)\n          debug \"Search path #{path} is not a directory\"\n        else\n          debug \"Search path #{path} does not exist\"\n        end","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/service/init.rb#L97-L133","documentation":"The init service provider's hasstatus= setter accepts exactly true, \"true\", false, or \"false\"; any other Ruby object raises Puppet::Error. This setter sits below the type-level validation of the hasstatus property, so it is normally only hit through programmatic use: provider instances built by hand, custom providers, or tests that poke @parameters directly instead of going through the property system.","triggerScenarios":"Calling provider.hasstatus = with a symbol (:true/:false), integer, or nil — for example provider.new(:name => 'x', :hasstatus => :true) in rspec-puppet tests, or a custom provider copying unconverted symbol values from the resource (@resource[:hasstatus] is the symbol :true at that layer, not the boolean true).","commonSituations":"Writing provider specs or custom service providers that pass @resource[:hasstatus] straight through; using puppet resource service <name> hasstatus=<odd value>; DSL-level mistakes are usually caught earlier by the property validation, so this is chiefly a developer-facing error.","solutions":["Pass booleans or their exact string forms: true, false, 'true', 'false'","Convert symbols before assignment: value.to_s == 'true' style normalization","Set hasstatus via the resource property in manifests (hasstatus => true) instead of mutating provider parameters"],"exampleFix":"# before\nprovider.hasstatus = @resource[:hasstatus] # :true symbol -> raises\n\n# after\nprovider.hasstatus = (@resource[:hasstatus].to_s == 'true')","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"# Ruby guard before calling the setter\ndef valid_hasstatus?(value)\n  [true, false, 'true', 'false'].include?(value)\nend\n\nraise ArgumentError, \"bad hasstatus: #{value.inspect}\" unless valid_hasstatus?(v)\nprovider.hasstatus = v","tryCatchPattern":"begin\n  provider.hasstatus = v\nrescue Puppet::Error\n  provider.hasstatus = v.to_s == 'true' # normalize and retry once\nend","preventionTips":["Remember @resource[:hasstatus] is the symbol :true at provider level — convert with .to_s before assigning","Prefer setting hasstatus as a resource property in manifests; the type layer validates values for you","Cover the setter in provider specs with both booleans and string forms to catch regressions"],"tags":["puppet","init","service","hasstatus","parameter-validation"],"backgroundTag":"invalid-parameter-value","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}