Skip to content

Commit c4ebf23

Browse files
author
Gerard Hickey
committed
Exception processing added to all Facter modules
1 parent eafb0e2 commit c4ebf23

File tree

7 files changed

+55
-8
lines changed

7 files changed

+55
-8
lines changed

hanlon_microkernel/facter/hnl_mk_bus.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@
1717
unless definition.empty?
1818
lines = definition.split(/\n/)
1919
item = lines.shift.tr(':', '')
20-
attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v] } ]
20+
attribs = Hash[ lines.collect do |l|
21+
begin
22+
l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
23+
rescue NoMethodError
24+
if Facter.debugging?
25+
puts "Error: (bus class) unable to parse #{l}"
26+
end
27+
end
28+
end ]
2129
results[item] = attribs
2230
end
2331
end

hanlon_microkernel/facter/hnl_mk_cpu.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
unless cpu =~ /disabled/i
2121
cpus += 1
2222
# Create a hash of attributes for each section (i.e. cpu)
23-
attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v] } ]
23+
attribs = Hash[ lines.collect do |l|
24+
begin
25+
l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
26+
rescue NoMethodError
27+
if Facter.debugging?
28+
puts "Error: (cpu class) unable to parse #{l}"
29+
end
30+
end
31+
end ]
2432
attribs.each_pair do |attrib, val|
2533
Facter.add("mk_hw_#{cpu}_#{attrib}") do
2634
setcode { val }

hanlon_microkernel/facter/hnl_mk_disk.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919
disk = lines.shift.tr(':', '')
2020
disks += 1
2121
# Create a hash of attributes for each section (i.e. cpu)
22-
attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v] } ]
22+
attribs = Hash[ lines.collect do |l|
23+
begin
24+
l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
25+
rescue NoMethodError
26+
if Facter.debugging?
27+
puts "Error: (disk class) unable to parse #{l}"
28+
end
29+
end
30+
end ]
2331
attribs.each_pair do |attrib, val|
2432
Facter.add("mk_hw_#{disk}_#{attrib}") do
2533
setcode { val }

hanlon_microkernel/facter/hnl_mk_mem.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,14 @@ def def_to_hash(definition, delimiter=':')
8787
else
8888
# no sub-definitions, just process the attributes
8989
result.merge! Hash[
90-
definition.split(/\n/).collect do |l|
91-
l =~ /^\s*([^#{delimiter}]+)#{delimiter}\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
90+
definition.split(/\n/).collect do |l|
91+
begin
92+
l =~ /^\s*([^#{delimiter}]+)#{delimiter}\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
93+
rescue NoMethodError
94+
if Facter.debugging?
95+
puts "Error: (memory class) unable to parse #{l}"
96+
end
97+
end
9298
end
9399
]
94100
end

hanlon_microkernel/facter/hnl_mk_nic.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919
network = lines.shift.tr(':', '')
2020
nics += 1
2121
# Create a hash of attributes for each section (i.e. cpu)
22-
attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v] } ]
22+
attribs = Hash[ lines.collect do |l|
23+
begin
24+
l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
25+
rescue NoMethodError
26+
if Facter.debugging?
27+
puts "Error: (network class) unable to parse #{l}"
28+
end
29+
end ]
2330
attribs.each_pair do |attrib, val|
2431
Facter.add("mk_hw_#{network}_#{attrib}") do
2532
setcode { val }

hanlon_microkernel/facter/hnl_mk_sys.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
begin
2222
l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
2323
rescue NoMethodError
24-
puts "Error: (system class) unable to parse %{l}"
24+
if Facter.debugging?
25+
puts "Error: (system class) unable to parse #{l}"
26+
end
2527
end
2628
end ]
2729
attribs.each_pair do |attrib, val|

hanlon_microkernel/facter/hnl_mk_vol.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919
volume = lines.shift.tr(':', '') and vols += 1
2020

2121
# Create a hash of attributes for each section (i.e. cpu)
22-
attribs = Hash[ lines.collect { |l| l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v] } ]
22+
attribs = Hash[ lines.collect do |l|
23+
begin
24+
l =~ /^\s*([^:]+):\s+(.*)\s*$/; v=$2; [$1.gsub(/\s/, '_'), v]
25+
rescue NoMethodError
26+
if Facter.debugging?
27+
puts "Error: (volume class) unable to parse #{l}"
28+
end
29+
end
30+
end ]
2331
attribs.each_pair do |attrib, val|
2432
Facter.add("mk_hw_#{volume}_#{attrib}") do
2533
setcode { val }

0 commit comments

Comments
 (0)