This week we talk about failure flags and benign values, report failure reporting, and warning as errors.
Failure flags and benign values
Sometimes responding with a nil
is good enough, i.e.
def save
# some failing code
rescue
nil
end
Related to this is the concept of "benign values"
The system might replace the erroneous value with a phony value that it knows to have a benign effect on the rest of the system
When the system's success doesn't depend on the outcome of the method in question, using a benign value may be the right choice. Benign values are also helpful in making the code more testable.
Example:
begin
response = HTTP.get_response(url)
JSON.parse(response.body)
rescue Net::HTTPError
{ 'stock_quote' => '' }
end
'ing, we can use
warn`Warning as errors
Check out this hack:
module Kernel
def warn(message)
raise message
end
end
warn 'uh oh'
Remote failure reporting
Circuit breaker pattern
Ending the program
exit
ends the whole programexit
in the Whiz Tutor codebase?John: User Onboard - https://www.useronboard.com/ by https://twitter.com/samuelhulick
JP: singlediv.com - https://twitter.com/samuelhulick