robustly 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -7
- data/lib/robustly.rb +4 -1
- data/lib/robustly/version.rb +1 -1
- data/test/robustly_test.rb +21 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca4ab42ad4c9c82369991b01dcada93a3a58138e
|
4
|
+
data.tar.gz: e2bbafae919d162f320e9f1632bb054fe1eeae07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 988758ad8ae65d80cb04f2bc4c25ee6d31c595c5427541bd9561310888065bba57d0b7b33068bb13974cf60bee7206a1a69471d5bb194293dd10edcd7aa7b475
|
7
|
+
data.tar.gz: 37dc2e5d78b0d5921924bca8d0cd888cce520ff72063ce0799df974f3413e3b0c88ddea5dc88230889b77e306ca1b1ad7a92d0f8b2f4bb7844f51c05b7ce1ea8
|
data/README.md
CHANGED
@@ -10,15 +10,15 @@ end
|
|
10
10
|
|
11
11
|
Raises exceptions in development and test environments and rescues and reports exceptions elsewhere.
|
12
12
|
|
13
|
-
Also aliased
|
13
|
+
Also aliased as `yolo`.
|
14
14
|
|
15
15
|
```ruby
|
16
16
|
yolo do
|
17
|
-
#
|
17
|
+
# get crazy in here
|
18
18
|
end
|
19
19
|
```
|
20
20
|
|
21
|
-
Reports exceptions to [Rollbar](https://rollbar.com/), [
|
21
|
+
Reports exceptions to [Rollbar](https://rollbar.com/), [Airbrake](https://airbrake.io/), [Exceptional](http://www.exceptional.io/), [Honeybadger](https://www.honeybadger.io/), [Sentry](https://getsentry.com/), [Raygun](https://raygun.io/), and [Bugsnag](https://bugsnag.com/) out of the box thanks to [Errbase](https://github.com/ankane/errbase).
|
22
22
|
|
23
23
|
Customize reporting with:
|
24
24
|
|
@@ -34,6 +34,22 @@ robustly throttle: 1000 do
|
|
34
34
|
end
|
35
35
|
```
|
36
36
|
|
37
|
+
Specify a default value to return on errors:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
robustly default: 30 do
|
41
|
+
# big bucks, no whammy
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
Catch specific errors
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
robustly only: ActiveRecord::RecordNotUnique do
|
49
|
+
# all other exceptions will be raised
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
37
53
|
## Installation
|
38
54
|
|
39
55
|
Add this line to your application’s Gemfile:
|
@@ -42,10 +58,6 @@ Add this line to your application’s Gemfile:
|
|
42
58
|
gem 'robustly'
|
43
59
|
```
|
44
60
|
|
45
|
-
## TODO
|
46
|
-
|
47
|
-
- ability to catch specific errors
|
48
|
-
|
49
61
|
## Contributing
|
50
62
|
|
51
63
|
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
data/lib/robustly.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "robustly/version"
|
2
|
+
require "errbase"
|
2
3
|
|
3
4
|
module Robustly
|
4
5
|
|
@@ -17,13 +18,15 @@ module Robustly
|
|
17
18
|
module Methods
|
18
19
|
|
19
20
|
def robustly(options = {}, &block)
|
21
|
+
class_names = Array(options[:only] || StandardError)
|
20
22
|
begin
|
21
23
|
yield
|
22
|
-
rescue => e
|
24
|
+
rescue *class_names => e
|
23
25
|
raise e if %w[development test].include?(Robustly.env)
|
24
26
|
if options[:throttle] ? rand < 1.0 / options[:throttle] : true
|
25
27
|
Robustly.report_exception(e)
|
26
28
|
end
|
29
|
+
options[:default]
|
27
30
|
end
|
28
31
|
end
|
29
32
|
alias_method :yolo, :robustly
|
data/lib/robustly/version.rb
CHANGED
data/test/robustly_test.rb
CHANGED
@@ -4,6 +4,7 @@ class TestRobustly < Minitest::Test
|
|
4
4
|
|
5
5
|
def setup
|
6
6
|
Robustly.env = "production"
|
7
|
+
Robustly.report_exception_method = proc {|e| Errbase.report(e) }
|
7
8
|
end
|
8
9
|
|
9
10
|
def test_robustly_development_environment
|
@@ -46,4 +47,24 @@ class TestRobustly < Minitest::Test
|
|
46
47
|
assert mock.verify
|
47
48
|
end
|
48
49
|
|
50
|
+
def test_return_value
|
51
|
+
assert_equal 1, robustly { 1 }
|
52
|
+
assert_equal nil, robustly { raise Robustly::TestError }
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_default
|
56
|
+
assert_equal 1, robustly(default: 2) { 1 }
|
57
|
+
assert_equal 2, robustly(default: 2) { raise Robustly::TestError }
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_only
|
61
|
+
assert_equal nil, robustly(only: Robustly::TestError) { raise Robustly::TestError }
|
62
|
+
assert_raises(RuntimeError, "Boom") { robustly(only: Robustly::TestError) { raise RuntimeError.new("Boom") } }
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_only_array
|
66
|
+
assert_equal nil, robustly(only: [Robustly::TestError]) { raise Robustly::TestError }
|
67
|
+
assert_raises(RuntimeError, "Boom") { robustly(only: [Robustly::TestError]) { raise RuntimeError.new("Boom") } }
|
68
|
+
end
|
69
|
+
|
49
70
|
end
|