Skip to content

Commit 44728ef

Browse files
author
Zach Leslie
committed
Check that we have results before returning a value
Without this change, empty results yield a message like the following in Facter output. undefined method `[]' for nil:NilClass This work captures the results and check to them to ensure we return a valid value.
1 parent 2111486 commit 44728ef

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

lib/facter/python_version.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
def get_python_version(executable)
44
if Facter::Util::Resolution.which(executable)
5-
Facter::Util::Resolution.exec("#{executable} -V 2>&1").match(/^.*(\d+\.\d+\.\d+)$/)[1]
5+
results = Facter::Util::Resolution.exec("#{executable} -V 2>&1").match(/^.*(\d+\.\d+\.\d+)$/)
6+
if results
7+
results[1]
8+
end
69
end
710
end
811

0 commit comments

Comments
 (0)