README.md in safely_block-0.1.0 vs README.md in safely_block-0.1.1

- old
+ new

@@ -1,51 +1,41 @@ # Safely -Unexpected data can cause errors in production - don’t let it bring down the system - ```ruby safely do # keep going if this code fails end ``` -Exceptions are rescued and reported to your favorite reporting service. +Exceptions are rescued and automatically reported to your favorite reporting service. -In development and test environments, exceptions are raised so you can fix them. :smirk: +In development and test environments, exceptions are raised so you can fix them. -## Examples +## Use It Everywhere -Great for analytics +“Oh no, analytics brought down search” ```ruby -safely { track_event("Search") } +safely { track_search(params) } ``` -and background jobs +“Recommendations stopped updating because of one bad user” ```ruby -User.find_each do |user| - safely { cache_recommendations(user) } +users.each do |user| + safely { update_recommendations(user) } end ``` Also aliased as `yolo`. ## Features -Throttle reporting with: - -```ruby -safely sample: 1000 do - # reports ~ 1/1000 errors -end -``` - Specify a default value to return on exceptions ```ruby -score = safely(default: 30) { calculate_score } +show_banner = safely(default: true) { show_banner_logic } ``` Raise specific exceptions ```ruby @@ -68,10 +58,20 @@ ```ruby safely(silence: ActiveRecord::RecordNotUnique) { code } ``` +Throttle reporting with: + +```ruby +safely throttle: {limit: 10, period: 1.minute} do + # reports only first 10 exceptions each minute +end +``` + +**Note:** The throttle limit is approximate and per process. + ## Reporting Reports exceptions to a variety of services out of the box thanks to [Errbase](https://github.com/ankane/errbase). - [Rollbar](https://rollbar.com/) @@ -92,9 +92,15 @@ By default, exception messages are prefixed with `[safely]`. This makes it easier to spot rescued exceptions. Turn this off with: ```ruby Safely.tag = false +``` + +To report exceptions manually: + +```ruby +Safely.report_exception(e) ``` ## Installation Add this line to your application’s Gemfile: