有时候,尽管出错了,但是错误的原因完全是个意外,甚至是不可知的,我们想再试试怎么办:
# 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跑到我们的视野中,搞的我们花费了大量时间去处理一个完全的孤立的意外。