Bug #5410

facter does not use return codes

Added by Garrett Honeycutt over 1 year ago. Updated 2 months ago.

Status:Accepted Start date:11/30/2010
Priority:Normal Due date:
Assignee:Paul Nasrat % Done:

0%

Category:binary
Target version:-
Keywords: Affected Facter version:
Branch:
Votes: 1

Description

It appears that facter always returns zero

Reproduction:

# facter operatingsystem
CentOS
# echo $?
0

# facter thisfactdoesnotexist
# echo $?
0

Supposing that the fact ‘thisfactdoesnotexist’ is not a valid fact name, the return code should not be zero.

History

Updated by James Turnbull over 1 year ago

  • Category set to binary
  • Status changed from Unreviewed to Needs Decision
  • Assignee set to Paul Nasrat

Updated by Garrett Honeycutt over 1 year ago

Here is another use case where facter does the wrong thing by returning zero.

Created a simple custom fact with the following code

require 'facter'
Facter.add("role") do
    setcode do
           %x{cat /etc/role}.chomp
             end
end

but did not create the /etc/role file

# facter role
cat: /etc/role: No such file or directory
cat: /etc/role: No such file or directory
# echo $?
0

Updated by Paul Nasrat over 1 year ago

I agree with the case for non-zero code for no matching facts, however the case of the fact above is really a poorly written fact (not to say there aren’t those in facter core atm!) which isn’t handling stuff gracefully. A resolution failing should not cause an error code from facter as it is normal operation to try multiple resolutions.

Updated by Garrett Honeycutt over 1 year ago

Glad that we agree upon the first case. Given that, I have created a separate ticket (#5440) to discuss the cases of poorly written facts.

https://projects.puppetlabs.com/issues/5440

Updated by Paul Nasrat over 1 year ago

  • Status changed from Needs Decision to Accepted

Looking at this there are a few inconsistencies we should fix at the same time, the quick fix for this bug is to add an exit condition for the single fact case – cf

https://gist.github.com/749923

However if you call multiple non-existent facts eg facter foo bar baz then it was returning

foo => bar => baz =>

Which is clearly quite odd. The above gist fixes that by only printing if an actual value, but we probably also want to exit non-zero in that case. We possibly could do something like

https://gist.github.com/749938

Updated by Ken Barber 6 months ago

  • Target version set to 186

Updated by Daniel Pittman 2 months ago

  • Target version deleted (186)

Also available in: Atom PDF