Retrying transient errors
It's a fact of life, at least for a programmer, that some things fail all the time, but other things only fail occasionally. For those things that fail all the time, there is no point in retrying them. For example, if you call a method and it raises ArgumentError
because you are calling it with the wrong number of arguments, as shown here:
nil.to_s(16)
You probably don't want to retry the preceding code, unless you expect that something will be redefining the NilClass#to_s
method to accept an argument.
However, in many cases, especially those involving network requests, it is very common to encounter transient errors. In these cases, retrying errors makes sense. When making a network request, there may be multiple reasons why it may fail. Maybe the program at the other end of the request crashed and is being restarted. Maybe a construction crew accidentally cut a network cable between your computer and the computer you are connecting to...