From 5019664d4d793ce52152558dac0b5ed5555273d6 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Fri, 18 Sep 2015 10:51:18 +0200 Subject: [PATCH] bugfix: catch cases, where no service is available --- lib/resources/service.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/resources/service.rb b/lib/resources/service.rb index 709088372..9feb02901 100644 --- a/lib/resources/service.rb +++ b/lib/resources/service.rb @@ -311,8 +311,11 @@ class WindowsSrv < ServiceManager return nil end - service['Service']['Status'] == 4 ? (running = true) : (running = false) - service['WMI']['StartMode'] == 'Auto' ? (enabled = true) : (enabled = false) + # check that we got a response + return nil if service.nil? || service['Service'].nil? + + (!service['Service'].nil? && !service['Service']['Status'].nil? && service['Service']['Status'] == 4) ? (running = true) : (running = false) + (!service['WMI'].nil? && !service['WMI']['StartMode'].nil? && service['WMI']['StartMode'] == 'Auto') ? (enabled = true) : (enabled = false) { name: service['Service']['Name'],