Details
-
Bug
-
Status: Resolved
-
Normal
-
Resolution: Fixed
-
FACT 4.0.52
-
None
-
Night's Watch
-
3
-
NW - 2021-04-14
-
Needs Assessment
-
Bug Fix
-
Fix Facter showing misleading values or errors when querying for non-existent facts via CLI and Facter.value.
-
Needs Assessment
Description
When you query for a custom structured fact, Facter uses Hash#dig to cicle through keys, but this can fail if the value of one of the cicled keys is not a Hash.
Simple ruby example:
❯ ruby -e '{"a" => "b"}.dig("a", "z")' |
Traceback (most recent call last):
|
1: from -e:1:in `<main>' |
-e:1:in `dig': String does not have #dig method (TypeError) |
Steps to reproduce in Facter:
1. create a custom fact
Facter.add('foo.bar') do |
setcode { 'baz' } |
end |
Query for that fact name and an extra key:
❯ bx facter foo.bar.x
|
|
facter-4.0.52/lib/facter/framework/formatters/formatter_helper.rb:28:in `dig': String does not have #dig method (TypeError) |
Same for Facter.value
2.7.2 :001 > require 'facter' |
2.7.2 :003 > Facter.value('foo.bar.x') |
facter-4.0.52/lib/facter/models/fact_collection.rb:22:in `block in value' |
NoMethodError (undefined method `fetch' for "baz":String) |
Another thing is that even for core facts, Facter ignores parts of the query, if it is partial matched:
❯ bx facter os.family.xyz
|
Darwin
|
|
2.7.2 :006 > Facter.value('os.family.a.b') |
=> "Darwin" |