有時候,盡管出錯了,但是錯誤的原因完全是個意外,甚至是不可知的,我們想再試試怎么辦:
# create string of all args
args = ""
ARGV.each { |arg| args+=" "+arg }
f = File.open("errors.log") or die "Unable to open file..."
# start with an empty array
errors=[]
f.each_line {|line|
errors.push line
}
if errors.length > 0
puts 'Attempting to resolve errors'
try = 1
while try <= 3
puts "Try number: "+try.to_s
errors.each_with_index{|name, i|
test = /(.+?)((.+?))/.match(name)
if system "ruby ""+test[2]+".rb"+args+"""
errors[i] = false
end
}
errors.delete(false)
if errors.length == 0
puts 'All errors resolved successfully!'
break
end
try+=1
end
File.open('errors.log', 'w'){|f|
errors.each{|error|
f << error
f << "
"
}
}
if errors.length != 0
puts 'Errors unresolved'
end
else
puts 'There are no errors in errors.log'
end
我們等于要把log中的error都再次過濾一下,從而使得有些可以避免的error跑到我們的視野中,搞的我們花費了大量時間去處理一個完全的孤立的意外。