Merge pull request #186 from stschulte/feature/master/12790
(#12790) Raise an exception if recursion is detected
Daniel Pittman
12 years ago
99 | 99 |
|
100 | 100 |
# Lock our searching process, so we never ge stuck in recursion.
|
101 | 101 |
def searching
|
102 | |
if searching?
|
103 | |
Facter.debug "Caught recursion on %s" % @name
|
104 | |
|
105 | |
# return a cached value if we've got it
|
106 | |
if @value
|
107 | |
return @value
|
108 | |
else
|
109 | |
return nil
|
110 | |
end
|
111 | |
end
|
|
102 |
raise RuntimeError, "Caught recursion on #{@name}" if searching?
|
112 | 103 |
|
113 | 104 |
# If we've gotten this far, we're not already searching, so go ahead and do so.
|
114 | 105 |
@searching = true
|
23 | 23 |
Facter.reset
|
24 | 24 |
Facter.collection.should_not equal(old)
|
25 | 25 |
end
|
|
26 |
|
|
27 |
it "should raise an error if a recursion is detected" do
|
|
28 |
Facter.clear
|
|
29 |
Facter.add(:foo) do
|
|
30 |
confine :bar => 'some_value'
|
|
31 |
end
|
|
32 |
Facter.add(:bar) do
|
|
33 |
confine :foo => 'some_value'
|
|
34 |
end
|
|
35 |
lambda { Facter.value(:foo) }.should raise_error(RuntimeError, /Caught recursion on foo/)
|
|
36 |
end
|
|
37 |
|
26 | 38 |
end
|