{"record":{"id":"e3aa4868d10fcef9","repo":"puppetlabs/puppet","slug":"unknown-service-state-current-state-for-servi","errorCode":null,"errorMessage":"Unknown service state '%{current_state}' for service '%{resource_name}'","messagePattern":"Unknown service state '%(.+?)' for service '%(.+?)'","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"warning","filePath":"lib/puppet/provider/service/windows.rb","lineNumber":104,"sourceCode":"  end\n\n  def stop\n    Puppet::Util::Windows::Service.stop(@resource[:name], timeout: @resource[:timeout])\n  end\n\n  def status\n    return :stopped unless Puppet::Util::Windows::Service.exists?(@resource[:name])\n\n    current_state = Puppet::Util::Windows::Service.service_state(@resource[:name])\n    state = case current_state\n            when :SERVICE_STOPPED, :SERVICE_STOP_PENDING\n              :stopped\n            when :SERVICE_PAUSED, :SERVICE_PAUSE_PENDING\n              :paused\n            when :SERVICE_RUNNING, :SERVICE_CONTINUE_PENDING, :SERVICE_START_PENDING\n              :running\n            else\n              raise Puppet::Error, _(\"Unknown service state '%{current_state}' for service '%{resource_name}'\") % { current_state: current_state, resource_name: @resource[:name] }\n            end\n    debug(\"Service #{@resource[:name]} is #{current_state}\")\n    state\n  rescue => detail\n    Puppet.warning(\"Status for service #{@resource[:name]} could not be retrieved: #{detail}\")\n    :stopped\n  end\n\n  def default_timeout\n    Puppet::Util::Windows::Service::DEFAULT_TIMEOUT\n  end\n\n  # returns all providers for all existing services and startup state\n  def self.instances\n    services = []\n    Puppet::Util::Windows::Service.services.each do |service_name, _|\n      services.push(new(:name => service_name))\n    end","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/provider/service/windows.rb#L86-L122","documentation":"Raised by Puppet's Windows service provider when the SCM reports a service state the provider cannot map to stopped/paused/running (mapped: STOPPED/STOP_PENDING, PAUSED/PAUSE_PENDING, RUNNING/CONTINUE_PENDING/START_PENDING). Practically it is an internal guard: the surrounding `rescue => detail` catches it, emits 'Puppet.warning(Status for service ... could not be retrieved: ...)' and falls back to :stopped, so the catalog run continues and the service gets started.","triggerScenarios":"A `status` query returning an unmapped state symbol — e.g., SERVICE_UNKNOWN or a transitional/undocumented state from an older or newer SCM helper — during ensure-sync or an explicit start/stop. The visible symptom is the warning line plus Puppet treating the service as stopped.","commonSituations":"Puppet version skew between agent and the Windows::Service helper's state list; services in unusual driver/kernel states; tests stubbing service_state with unexpected symbols. Low operational impact because of the built-in fallback.","solutions":["Check the accompanying warning for the raw state value and query the node: `Get-Service <name>` / `sc.exe query <name>`.","If the state is transitional (start/pause pending), wait and re-run; the service usually settles into a mapped state.","Upgrade the Puppet agent so the SCM helper's state list covers the reported state.","If the fallback (:stopped) causes an unwanted start, set `ensure => stopped` or use `hasstatus => false`-style manual checks appropriate to your Puppet version."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"state = Puppet::Util::Windows::Service.service_state('myapp')\nknown = %i[SERVICE_STOPPED SERVICE_STOP_PENDING SERVICE_PAUSED SERVICE_PAUSE_PENDING SERVICE_RUNNING SERVICE_CONTINUE_PENDING SERVICE_START_PENDING]\nwarn 'unmapped SCM state' unless known.include?(state)","typeGuard":"MAPPED_STATES = %i[SERVICE_STOPPED SERVICE_STOP_PENDING SERVICE_PAUSED SERVICE_PAUSE_PENDING SERVICE_RUNNING SERVICE_CONTINUE_PENDING SERVICE_START_PENDING].freeze\n\ndef puppet_status_symbol(scm_state)\n  case scm_state\n  when :SERVICE_STOPPED, :SERVICE_STOP_PENDING then :stopped\n  when :SERVICE_PAUSED, :SERVICE_PAUSE_PENDING then :paused\n  when :SERVICE_RUNNING, :SERVICE_CONTINUE_PENDING, :SERVICE_START_PENDING then :running\n  end # nil for unmapped\nend","tryCatchPattern":null,"preventionTips":["Remember the built-in fallback: unknown state becomes a warning plus :stopped, so ensure => stopped is the safe declaration for exotic services.","Verify the real state with `sc.exe query` after runs that emit the warning.","Keep agent versions aligned with your Windows fleet so mapped state lists stay complete."],"tags":["windows","service-management","puppet","scm","status"],"backgroundTag":"unknown-service-state","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}