safely_block 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -0
- data/CHANGELOG.md +4 -0
- data/README.md +2 -0
- data/lib/safely/core.rb +10 -10
- data/lib/safely/version.rb +1 -1
- data/test/safely_test.rb +11 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0de79be5d7e0795c8a2e1497590a89685074a744
|
4
|
+
data.tar.gz: 33632c2284079dea7fef3c8d94a0903691402f34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9082a7502e3b3df897c3fed0b968bb7d950bfc0fb44f86e3d51b4b5ee3aca867a8cddf6b49f78c1f9df96eda653cc2607c8dceabd5e888560cbbabe3722bb7fd
|
7
|
+
data.tar.gz: 3c5c86c9e3609db1b03e76cfb2eb723ee82d7e0a3bf4a5a18374dd96aaf7526e90d305aa9ee8f4f525fa3bf153ff35a7a6b232baa5912b8ff126a9272ca106a0
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,8 @@ Exceptions are rescued and automatically reported to your favorite reporting ser
|
|
10
10
|
|
11
11
|
In development and test environments, exceptions are raised so you can fix them.
|
12
12
|
|
13
|
+
[![Build Status](https://travis-ci.org/ankane/safely.svg?branch=master)](https://travis-ci.org/ankane/safely)
|
14
|
+
|
13
15
|
## Use It Everywhere
|
14
16
|
|
15
17
|
“Oh no, analytics brought down search”
|
data/lib/safely/core.rb
CHANGED
@@ -7,7 +7,15 @@ module Safely
|
|
7
7
|
attr_accessor :raise_envs, :tag, :report_exception_method, :throttle_counter
|
8
8
|
attr_writer :env
|
9
9
|
|
10
|
-
def report_exception(e)
|
10
|
+
def report_exception(e, tag: nil)
|
11
|
+
tag = Safely.tag if tag.nil?
|
12
|
+
if tag && e.message
|
13
|
+
e = e.dup # leave original exception unmodified
|
14
|
+
message = e.message
|
15
|
+
e.define_singleton_method(:message) do
|
16
|
+
"[#{tag == true ? "safely" : tag}] #{message}"
|
17
|
+
end
|
18
|
+
end
|
11
19
|
report_exception_method.call(e)
|
12
20
|
end
|
13
21
|
|
@@ -42,15 +50,7 @@ module Safely
|
|
42
50
|
if sample ? rand < 1.0 / sample : true
|
43
51
|
begin
|
44
52
|
unless Array(silence).any? { |c| e.is_a?(c) } || Safely.throttled?(e, throttle)
|
45
|
-
|
46
|
-
if tag && e.message
|
47
|
-
e = e.dup # leave original exception unmodified
|
48
|
-
message = e.message
|
49
|
-
e.define_singleton_method(:message) do
|
50
|
-
"[#{tag == true ? "safely" : tag}] #{message}"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
Safely.report_exception(e)
|
53
|
+
Safely.report_exception(e, tag: tag)
|
54
54
|
end
|
55
55
|
rescue => e2
|
56
56
|
$stderr.puts "FAIL-SAFE #{e2.class.name}: #{e2.message}"
|
data/lib/safely/version.rb
CHANGED
data/test/safely_test.rb
CHANGED
@@ -69,6 +69,17 @@ class TestSafely < Minitest::Test
|
|
69
69
|
assert_equal "[hi] Boom", ex.message
|
70
70
|
end
|
71
71
|
|
72
|
+
def test_report_exception_tag
|
73
|
+
ex = nil
|
74
|
+
Safely.report_exception_method = -> (e) { ex = e }
|
75
|
+
begin
|
76
|
+
raise Safely::TestError, "Boom"
|
77
|
+
rescue => e
|
78
|
+
Safely.report_exception(e)
|
79
|
+
end
|
80
|
+
assert_equal "[safely] Boom", ex.message
|
81
|
+
end
|
82
|
+
|
72
83
|
def test_return_value
|
73
84
|
assert_equal 1, safely { 1 }
|
74
85
|
assert_nil safely { raise Safely::TestError, "Boom" }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: safely_block
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: errbase
|
@@ -74,6 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
77
78
|
- CHANGELOG.md
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
@@ -105,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
106
|
version: '0'
|
106
107
|
requirements: []
|
107
108
|
rubyforge_project:
|
108
|
-
rubygems_version: 2.6.
|
109
|
+
rubygems_version: 2.6.13
|
109
110
|
signing_key:
|
110
111
|
specification_version: 4
|
111
112
|
summary: Awesome exception handling
|