mrhenry-failtale-reporter 0.0.5 → 0.1.0

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.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009 Mr.Henry
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -1,6 +1,6 @@
1
1
 
2
+ require 'digest/sha1'
2
3
  begin
3
- require 'digest/sha1'
4
4
  httparty = Dir.glob(File.dirname(__FILE__)+'/../vendor/httparty-*/lib/httparty.rb').last
5
5
  httparty ||= 'httparty'
6
6
  require httparty
@@ -34,15 +34,85 @@ module FailtaleReporter
34
34
  @default_reporter = reporter if reporter
35
35
  @default_reporter
36
36
  end
37
+ def application_root(path=nil)
38
+ @application_root = backtrace_cleaner_regexp(path) if path
39
+ @application_root
40
+ end
37
41
  def configure
38
42
  yield self
39
43
  end
44
+ def clean_backtrace(backtrace)
45
+ backtrace.collect do |line|
46
+ path = File.expand_path(line.split(':').first)
47
+ if File.exist?(path)
48
+ line = File.expand_path(line)
49
+ cleaned_line = nil
50
+ backtrace_cleaners.each do |proc|
51
+ cleaned_line = proc.call(line)
52
+ break if cleaned_line
53
+ end
54
+ cleaned_line || line
55
+ else
56
+ line
57
+ end
58
+ end
59
+ end
60
+ def backtrace_cleaners
61
+ @backtrace_cleaners ||= []
62
+ end
63
+ def backtrace_cleaner(&block)
64
+ backtrace_cleaners.push(block)
65
+ end
66
+ def backtrace_cleaner_regexp(path)
67
+ Regexp.new("^#{Regexp.escape(File.expand_path(path))}")
68
+ end
69
+ def collect_information(error, ctxs)
70
+ information_collectors.each do |proc|
71
+ proc.call(error, *ctxs)
72
+ end
73
+ end
74
+ def information_collectors
75
+ @information_collectors ||= []
76
+ end
77
+ def information_collector(&block)
78
+ information_collectors.push(block)
79
+ end
40
80
  end
41
81
 
42
82
  default_reporter 'ruby'
43
83
 
44
- def self.report(error=nil, &block)
45
- Client.new.report(error, &block)
84
+ backtrace_cleaner do |line|
85
+ if FailtaleReporter.application_root
86
+ line.sub! FailtaleReporter.application_root, "[APP]"
87
+ end
88
+ end
89
+
90
+ if defined?(Gem)
91
+ class << self
92
+ def gem_backtrace_cleaner(spec)
93
+ @gem_backtrace_cleaner ||= {}
94
+ unless @gem_backtrace_cleaner[spec.full_name]
95
+ @gem_backtrace_cleaner[spec.full_name] = {
96
+ :regexp => backtrace_cleaner_regexp(spec.full_gem_path),
97
+ :label => "[GEM: #{spec.name} @#{spec.version.to_s}]"
98
+ }
99
+ end
100
+ @gem_backtrace_cleaner[spec.full_name]
101
+ end
102
+ end
103
+ backtrace_cleaner do |line|
104
+ cleaned_line = nil
105
+ Gem.loaded_specs.values.each do |spec|
106
+ options = FailtaleReporter.gem_backtrace_cleaner(spec)
107
+ cleaned_line = line.sub!(options[:regexp], options[:label])
108
+ break if cleaned_line
109
+ end
110
+ cleaned_line
111
+ end
112
+ end
113
+
114
+ def self.report(error=nil, *ctxs, &block)
115
+ Client.new.report(error, *ctxs, &block)
46
116
  end
47
117
 
48
118
  end
@@ -18,11 +18,20 @@ module FailtaleReporter
18
18
  FailtaleReporter.configure do |config|
19
19
  config.ignored_exceptions IGNORED_EXCEPTIONS
20
20
  config.default_reporter "rails"
21
+ config.application_root RAILS_ROOT
22
+ config.information_collector do |error, controller|
23
+ env = error.environment
24
+ env = env.merge(controller.request.env)
25
+
26
+ env.delete('action_controller.rescue.response')
27
+ env.delete('action_controller.rescue.request')
28
+ error.environment = env
29
+ end
21
30
  end
22
31
  end
23
32
 
24
33
  def rescue_action_in_public_with_failtale(exception)
25
- FailtaleReporter.report(exception) unless is_private?
34
+ FailtaleReporter.report(exception, self) unless is_private?
26
35
  rescue_action_in_public_without_failtale(exception)
27
36
  end
28
37
 
@@ -2,11 +2,11 @@
2
2
  module FailtaleReporter
3
3
  class Client
4
4
 
5
- def report(error=nil)
6
- error = handle_exception(error)
5
+ def report(error=nil, *ctxs)
6
+ error = handle_exception(error, ctxs)
7
7
  yield if block_given? and error.nil?
8
8
  rescue Exception => exception
9
- error = handle_exception(exception)
9
+ error = handle_exception(exception, ctxs)
10
10
  ensure
11
11
  post_report(error) unless error.nil?
12
12
  raise exception unless exception.nil?
@@ -14,12 +14,15 @@ module FailtaleReporter
14
14
 
15
15
  private
16
16
 
17
- def handle_exception(exception)
17
+ def handle_exception(exception, ctxs)
18
18
  return exception if exception.is_a? FailtaleReporter::Error
19
19
  return nil if exception.nil?
20
20
  return nil unless FailtaleReporter.reportable_exceptions.any? {|c| exception.is_a? c }
21
21
  return nil if FailtaleReporter.ignored_exceptions.any? {|c| exception.is_a? c }
22
- FailtaleReporter::Error.new(exception)
22
+ FailtaleReporter::Error.new(exception, ctxs)
23
+ rescue Exception => e
24
+ puts "#{e.class}: #{e.message}"
25
+ puts e.backtrace
23
26
  end
24
27
 
25
28
  def post_report(error)
@@ -11,17 +11,26 @@ module FailtaleReporter
11
11
  attr_accessor :backtrace
12
12
  attr_accessor :environment
13
13
 
14
- def initialize(exception)
14
+ def initialize(exception, ctxs=[])
15
15
  self.api_token = FailtaleReporter.api_token
16
16
  self.reporter = FailtaleReporter.default_reporter
17
17
 
18
18
  self.name = "#{exception.class} #{exception.message}"
19
19
  self.description = exception.message
20
- self.backtrace = exception.backtrace.join("\n")
20
+ self.backtrace = FailtaleReporter.clean_backtrace(exception.backtrace).join("\n")
21
21
  self.environment = ENV.to_hash
22
22
  self.hash_string = Digest::SHA1.hexdigest(
23
23
  [exception.class, exception.backtrace.first].join('--')
24
24
  )
25
+ FailtaleReporter.collect_information(self, ctxs)
26
+
27
+ self.backtrace = self.backtrace.inspect unless self.backtrace.is_a? String
28
+ self.environment = self.environment.inject({}) do |m,(k,v)|
29
+ k = k.inspect unless k.is_a? String
30
+ v = v.inspect unless v.is_a? String
31
+ m[k] = v
32
+ m
33
+ end
25
34
  end
26
35
 
27
36
  def to_param
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mrhenry-failtale-reporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Menke
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-10 00:00:00 -08:00
12
+ date: 2009-02-18 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -23,6 +24,7 @@ dependencies:
23
24
  version:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: httparty
27
+ type: :runtime
26
28
  version_requirement:
27
29
  version_requirements: !ruby/object:Gem::Requirement
28
30
  requirements:
@@ -49,6 +51,7 @@ files:
49
51
  - tasks/failtale.rake
50
52
  - spec/error_reporter_spec.rb
51
53
  - spec/error_spec.rb
54
+ - LICENSE.txt
52
55
  - README.textile
53
56
  has_rdoc: false
54
57
  homepage: http://github.com/mrhenry