rorvswild 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d51045f4d30998e878c0a5c3db82c8a519c6e41
4
- data.tar.gz: 53eb0bc8ffe92a7b53e9500af26b351f112edb65
3
+ metadata.gz: a6e52c1a22d430fa8b500f62fdd31f181167db81
4
+ data.tar.gz: 2f5733d3c6e7dc928d375f16a4aa73e11ec70ffd
5
5
  SHA512:
6
- metadata.gz: 78f0092c6e641139b0c75cbc4895be8ab0d5011292a309cdb871f3ed7a359a385d1766679e49342d09b93ef9cbca86b41a63b1de79312509dd321c5278f277c8
7
- data.tar.gz: c3c9f93f7bd26a1c8cee07946cc9a74a4c1dfa7a2a3f44449b90fee264ca278a7c56c89d7bda27f42213aea1873437042d9dc0ea4fb2a0003fd1d266054c5230
6
+ metadata.gz: 4cf9c4add4dc657ced2e51a965d3aa1506582a9c93f9e4176e66560715833b1dde19b2321b42b7bdbdddf537b0e7a32ceb90034b900119eaf9b63a49cb2af716
7
+ data.tar.gz: f8fda54c4b7cd69c6aa62100af1dccc2e0c36dc12d15d5a7992d92adc7afa0cf25b8d3ba7be6cbd13a1cdd80da0c4d23a0481618aa482f736060bc9b819fd3d6
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "0.0.8".freeze
2
+ VERSION = "0.0.9".freeze
3
3
  end
data/lib/rorvswild.rb CHANGED
@@ -26,6 +26,14 @@ module RorVsWild
26
26
  default_client ? default_client.measure_block(name , &block) : block.call
27
27
  end
28
28
 
29
+ def self.catch_error(extra_details = nil, &block)
30
+ default_client.catch_error(extra_details, &block) if default_client
31
+ end
32
+
33
+ def self.record_error(exception, extra_details = nil)
34
+ default_client.record_error(exception, extra_details) if default_client
35
+ end
36
+
29
37
  class Client
30
38
  def self.default_config
31
39
  {
@@ -104,15 +112,10 @@ module RorVsWild
104
112
  def after_exception(exception, controller)
105
113
  if !exception.is_a?(ActionController::RoutingError)
106
114
  file, line = exception.backtrace.first.split(":")
107
- @error = {
108
- line: line.to_i,
109
- file: relative_path(file),
110
- message: exception.message,
111
- backtrace: exception.backtrace,
112
- exception: exception.class.to_s,
115
+ @error = exception_to_hash(exception).merge(
113
116
  session: controller.session.to_hash,
114
117
  environment_variables: filter_sensitive_data(filter_environment_variables(controller.request.env))
115
- }
118
+ )
116
119
  end
117
120
  raise exception
118
121
  end
@@ -137,14 +140,7 @@ module RorVsWild
137
140
  cpu_time_offset = cpu_time
138
141
  block.call
139
142
  rescue => exception
140
- file, line = exception.backtrace.first.split(":")
141
- job[:error] = {
142
- line: line.to_i,
143
- file: relative_path(file),
144
- message: exception.message,
145
- backtrace: exception.backtrace,
146
- exception: exception.class.to_s,
147
- }
143
+ job[:error] = exception_to_hash(exception)
148
144
  raise
149
145
  ensure
150
146
  job[:runtime] = (Time.now - started_at) * 1000
@@ -152,6 +148,19 @@ module RorVsWild
152
148
  post_job
153
149
  end
154
150
 
151
+ def catch_error(extra_details = nil, &block)
152
+ begin
153
+ block.call
154
+ rescue => exception
155
+ record_error(exception, extra_details)
156
+ exception
157
+ end
158
+ end
159
+
160
+ def record_error(exception, extra_details = nil)
161
+ post_error(exception_to_hash(exception, extra_details))
162
+ end
163
+
155
164
  def cpu_time
156
165
  time = Process.times
157
166
  time.utime + time.stime + time.cutime + time.cstime
@@ -214,6 +223,10 @@ module RorVsWild
214
223
  log_error(exception)
215
224
  end
216
225
 
226
+ def post_error(hash)
227
+ post("/errors", error: hash)
228
+ end
229
+
217
230
  def extract_file_and_line_from_call_stack(stack)
218
231
  return unless location = stack.find { |str| str.include?(Rails.root.to_s) }
219
232
  file, line, method = location.split(":")
@@ -237,6 +250,18 @@ module RorVsWild
237
250
  path.sub(Rails.root.to_s, "")
238
251
  end
239
252
 
253
+ def exception_to_hash(exception, extra_details = nil)
254
+ file, line = exception.backtrace.first.split(":")
255
+ {
256
+ line: line.to_i,
257
+ file: relative_path(file),
258
+ message: exception.message,
259
+ backtrace: exception.backtrace,
260
+ exception: exception.class.to_s,
261
+ extra_details: extra_details,
262
+ }
263
+ end
264
+
240
265
  def post(path, data)
241
266
  uri = URI(api_url + path)
242
267
  Net::HTTP.start(uri.host, uri.port) do |http|
@@ -39,6 +39,23 @@ class RorVsWildTest < MiniTest::Unit::TestCase
39
39
  assert_equal(2, RorVsWild.measure_block("1+1") { 1+1 })
40
40
  end
41
41
 
42
+ def test_catch_error
43
+ client.expects(:post_error)
44
+ exception = RorVsWild.catch_error { 1 / 0 }
45
+ assert_equal(ZeroDivisionError, exception.class)
46
+ end
47
+
48
+ def test_catch_error_with_extra_Details
49
+ client.expects(:post_error)
50
+ exception = RorVsWild.catch_error(foo: "bar") { 1 / 0 }
51
+ assert_equal(ZeroDivisionError, exception.class)
52
+ end
53
+
54
+ def test_catch_error_when_no_errors
55
+ client.expects(:post_error).never
56
+ assert_equal(2, RorVsWild.catch_error { 1 + 1 })
57
+ end
58
+
42
59
  private
43
60
 
44
61
  def client
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rorvswild
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler