Robustly
Unexpected data can cause errors in production - don’t let it bring down the system
safely do
# keep going if this code fails
end
Exceptions are rescued and reported to your favorite reporting service.
In development and test environments, exceptions are raised so you can fix them. :smirk:
Examples
Great for analytics
safely { track_event("Search") }
and background jobs
User.find_each do |user|
safely { cache_recommendations(user) }
end
Also aliased as yolo
.
Features
Throttle reporting with:
safely sample: 1000 do
# reports ~ 1/1000 errors
end
Specify a default value to return on exceptions
score = safely(default: 30) { calculate_score }
Raise specific exceptions
safely except: ActiveRecord::RecordNotUnique do
# all other exceptions will be rescued
end
Pass an array for multiple exception classes.
Rescue only specific exceptions
safely only: ActiveRecord::RecordNotUnique do
# all other exceptions will be raised
end
Silence exceptions
safely(silence: ActiveRecord::RecordNotUnique) { code }
Reporting
Reports exceptions to a variety of services out of the box thanks to Errbase.
Customize reporting with:
Robustly.report_exception_method = proc { |e| Rollbar.error(e) }
By default, exception messages are prefixed with [safely]
. This makes it easier to spot rescued exceptions. Turn this off with:
Robustly.tag = false
Installation
Add this line to your application’s Gemfile:
gem 'robustly'
History
View the changelog
Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features