{"record":{"id":"cfcb018e1abc80c3","repo":"puppetlabs/puppet","slug":"unknown-service-state-current-state-for-se","errorCode":null,"errorMessage":"Unknown Service state '%{current_state}' for '%{service_name}'","messagePattern":"Unknown Service state '%(.+?)' for '%(.+?)'","errorType":"exception","errorClass":"Puppet::Error","httpStatus":null,"severity":"error","filePath":"lib/puppet/util/windows/service.rb","lineNumber":114,"sourceCode":"      end\n\n      Puppet.debug _(\"Successfully resumed the %{service_name} service\") % { service_name: service_name }\n    end\n    module_function :resume\n\n    # Query the state of a service using QueryServiceStatusEx\n    #\n    # @param [string] service_name name of the service to query\n    # @return [string] the status of the service\n    def service_state(service_name)\n      state = nil\n      open_service(service_name, SC_MANAGER_CONNECT, SERVICE_QUERY_STATUS) do |service|\n        query_status(service) do |status|\n          state = SERVICE_STATES[status[:dwCurrentState]]\n        end\n      end\n      if state.nil?\n        raise Puppet::Error, _(\"Unknown Service state '%{current_state}' for '%{service_name}'\") % { current_state: state.to_s, service_name: service_name }\n      end\n\n      state\n    end\n    module_function :service_state\n\n    # Query the configuration of a service using QueryServiceConfigW\n    # or QueryServiceConfig2W\n    #\n    # @param [String] service_name name of the service to query\n    # @return [QUERY_SERVICE_CONFIGW.struct] the configuration of the service\n    def service_start_type(service_name)\n      start_type = nil\n      open_service(service_name, SC_MANAGER_CONNECT, SERVICE_QUERY_CONFIG) do |service|\n        query_config(service) do |config|\n          start_type = SERVICE_START_TYPES[config[:dwStartType]]\n        end\n      end","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/puppetlabs/puppet/blob/e227c27540975c25aa22d533a52424a9d2fc886a/lib/puppet/util/windows/service.rb#L96-L132","documentation":"Raised by service_state when the numeric dwCurrentState returned by QueryServiceStatusEx has no entry in the SERVICE_STATES map (which covers all seven standard states 1-7). A nil lookup means the SCM reported an unmapped state value, which normally indicates an unexpected/undocumented value or a struct-reading problem. Note a message quirk: current_state is interpolated as state.to_s, and since state is nil at that point, the message always shows an empty state string.","triggerScenarios":"service_state on a service whose reported dwCurrentState is 0 or outside 1-7, e.g. a half-initialized driver service, a service in a transient state during SCM churn, or corrupted query results read into SERVICE_STATUS_PROCESS.","commonSituations":"Rare; occasionally seen against kernel drivers or immediately after service install/uninstall races; more often a symptom of FFI struct layout mismatch than of a genuinely novel state.","solutions":["Retry the query once after a short delay to rule out transient SCM state during install/uninstall","Cross-check with sc query <name> and PowerShell Get-Service to see the raw state","If reproducible, verify the ffi gem and Puppet versions are compatible (struct layout drift produces garbage state codes)","File the occurrence upstream with the service name and state code"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"def safe_service_state(name, attempts: 2)\n  Puppet::Util::Windows::Service.service_state(name)\nrescue Puppet::Error => e\n  retry if (attempts -= 1) > 0 && e.message.include?(\"Unknown Service state\")\n  raise Puppet::Error, \"SCM reported an unmapped state for #{name}; check 'sc query #{name}'\"\nend","preventionTips":["Remember the message shows an empty state string (nil interpolated) — the state code itself is in the SCM query, not the error","Retry once: transient SCM values during install/removal are the usual cause","Cross-check with sc query when it reproduces"],"tags":["windows","service","win32","state-machine","scm"],"backgroundTag":"unknown-service-state","analyzedSha":"e227c27540975c25aa22d533a52424a9d2fc886a","analyzedAt":"2026-08-21T20:49:46.650Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}