puppetlabs/puppet · error · Puppet::Error
Unknown Service state '%{current_state}' for '%{service_name
Error message
Unknown Service state '%{current_state}' for '%{service_name}' What it means
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.
Source
Thrown at lib/puppet/util/windows/service.rb:114
end
Puppet.debug _("Successfully resumed the %{service_name} service") % { service_name: service_name }
end
module_function :resume
# Query the state of a service using QueryServiceStatusEx
#
# @param [string] service_name name of the service to query
# @return [string] the status of the service
def service_state(service_name)
state = nil
open_service(service_name, SC_MANAGER_CONNECT, SERVICE_QUERY_STATUS) do |service|
query_status(service) do |status|
state = SERVICE_STATES[status[:dwCurrentState]]
end
end
if state.nil?
raise Puppet::Error, _("Unknown Service state '%{current_state}' for '%{service_name}'") % { current_state: state.to_s, service_name: service_name }
end
state
end
module_function :service_state
# Query the configuration of a service using QueryServiceConfigW
# or QueryServiceConfig2W
#
# @param [String] service_name name of the service to query
# @return [QUERY_SERVICE_CONFIGW.struct] the configuration of the service
def service_start_type(service_name)
start_type = nil
open_service(service_name, SC_MANAGER_CONNECT, SERVICE_QUERY_CONFIG) do |service|
query_config(service) do |config|
start_type = SERVICE_START_TYPES[config[:dwStartType]]
end
endView on GitHub (pinned to e227c27540)
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
Defensive patterns
Strategy: try-catch
Try / catch
def safe_service_state(name, attempts: 2)
Puppet::Util::Windows::Service.service_state(name)
rescue Puppet::Error => e
retry if (attempts -= 1) > 0 && e.message.include?("Unknown Service state")
raise Puppet::Error, "SCM reported an unmapped state for #{name}; check 'sc query #{name}'"
end Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The service must be in one of the %{valid_initial_states} st
- Unknown start type '%{start_type}' for '%{service_name}'
- Failed to fetch services
- Failed to open a handle to the service
- Failed to open a handle to the service control manager
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/cfcb018e1abc80c3.
Report an issue: GitHub.