Uploaded image for project: 'Facter'
  1. Facter
  2. FACT-2998

Facter breaks when querying for custom facts

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: FACT 4.0.52
    • Fix Version/s: FACT 4.1.0
    • Component/s: None
    • Labels:
    • Template:
    • Team:
      Night's Watch
    • Story Points:
      3
    • Sprint:
      NW - 2021-04-14
    • Method Found:
      Needs Assessment
    • Release Notes:
      Bug Fix
    • Release Notes Summary:
      Fix Facter showing misleading values or errors when querying for non-existent facts via CLI and Facter.value.
    • QA Risk Assessment:
      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"
      

        Attachments

          Activity

            People

            Assignee:
            gabriel.nagy Gabriel Nagy
            Reporter:
            gheorghe.popescu Gheorghe Popescu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Zendesk Support