From 44728efa617d8b486b27fef33b5b33b52c78137b Mon Sep 17 00:00:00 2001 From: Zach Leslie Date: Mon, 7 Sep 2015 19:24:27 +0000 Subject: [PATCH] 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. --- lib/facter/python_version.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/facter/python_version.rb b/lib/facter/python_version.rb index a08059bd..8fe91636 100644 --- a/lib/facter/python_version.rb +++ b/lib/facter/python_version.rb @@ -2,7 +2,10 @@ def get_python_version(executable) if Facter::Util::Resolution.which(executable) - Facter::Util::Resolution.exec("#{executable} -V 2>&1").match(/^.*(\d+\.\d+\.\d+)$/)[1] + results = Facter::Util::Resolution.exec("#{executable} -V 2>&1").match(/^.*(\d+\.\d+\.\d+)$/) + if results + results[1] + end end end