Skip to content

Commit 185aa9a

Browse files
author
Gerard Hickey
committed
Added exception handling to memory factor module for debugging
1 parent b0847ed commit 185aa9a

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

hanlon_microkernel/facter/hnl_mk_mem.rb

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,29 @@ def def_to_hash(definition, delimiter=':')
112112
# process the results from lshw -c memory
113113
memory = def_to_hash(lshw_c_memory_str)
114114

115-
# Create the facts for the firmware info
116-
%w{description vendor physical_id version date size capabilities capacity}.each do |fact|
117-
Facter.add("mk_hw_fw_#{fact}") do
118-
setcode { memory['firmware'][fact] }
115+
begin
116+
# Create the facts for the firmware info
117+
%w{description vendor physical_id version date size capabilities capacity}.each do |fact|
118+
Facter.add("mk_hw_fw_#{fact}") do
119+
setcode { memory['firmware'][fact] }
120+
end
119121
end
120-
end
121122

122-
# Create the facts for the memory info
123-
%w{description physical_id slot size }.each do |fact|
124-
Facter.add("mk_hw_mem_#{fact}") do
125-
setcode { memory['memory'][fact] }
123+
# Create the facts for the memory info
124+
%w{description physical_id slot size }.each do |fact|
125+
Facter.add("mk_hw_mem_#{fact}") do
126+
setcode { memory['memory'][fact] }
127+
end
126128
end
127-
end
128129

129-
slot_info = memory['memory']['bank_array'].select {|entry| entry['size']}
130-
Facter.add("mk_hw_mem_slot_info") do
131-
setcode { slot_info }
130+
slot_info = memory['memory']['bank_array'].select {|entry| entry['size']}
131+
Facter.add("mk_hw_mem_slot_info") do
132+
setcode { slot_info }
133+
end
134+
rescue Exception => e
135+
puts "Exception: #{e}"
132136
end
133137

134-
135138
# # next, the memory information (including firmware, system memory, and caches)
136139
# lshw_c_memory_str = %x[sudo #{lshw_cmd} -c memory 2> /dev/null]
137140
# hash_map = lshw_output_to_hash(lshw_c_memory_str, ":")

0 commit comments

Comments
 (0)