mrhenry-failtale-reporter 0.0.1
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.
- data/README.textile +24 -0
- data/lib/failtale-reporter.rb +2 -0
- data/lib/failtale_reporter.rb +62 -0
- data/lib/failtale_reporter/adapters/rails.rb +31 -0
- data/lib/failtale_reporter/error.rb +36 -0
- data/lib/mrhenry-failtale-reporter.rb +2 -0
- data/rails/init.rb +2 -0
- data/spec/error_reporter_spec.rb +33 -0
- data/spec/error_spec.rb +22 -0
- metadata +81 -0
data/README.textile
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
h2. LICENSE:
|
|
2
|
+
|
|
3
|
+
(The MIT License)
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2008 Mr. Henry
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
a copy of this software and associated documentation files (the
|
|
9
|
+
'Software'), to deal in the Software without restriction, including
|
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be
|
|
16
|
+
included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
21
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
22
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
23
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
24
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
|
|
2
|
+
begin
|
|
3
|
+
require 'digest/sha1'
|
|
4
|
+
require 'httparty'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
retry if require 'rubygems'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
require File.dirname(__FILE__)+'/failtale_reporter/error'
|
|
10
|
+
|
|
11
|
+
module ErrorReporter
|
|
12
|
+
|
|
13
|
+
include HTTParty
|
|
14
|
+
|
|
15
|
+
base_uri 'errors.be'
|
|
16
|
+
format :xml
|
|
17
|
+
|
|
18
|
+
def self.load_adapter(name)
|
|
19
|
+
require File.dirname(__FILE__)+"/failtale_reporter/adapters/#{name}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class << self
|
|
23
|
+
def reportable_exceptions(*arr)
|
|
24
|
+
arr = [Exception] if arr.empty?
|
|
25
|
+
@reportable_exceptions ||= arr.flatten
|
|
26
|
+
end
|
|
27
|
+
def ignored_exceptions(*arr)
|
|
28
|
+
@ignored_exceptions ||= arr.flatten
|
|
29
|
+
end
|
|
30
|
+
def api_token(token=nil)
|
|
31
|
+
@api_token ||= token
|
|
32
|
+
end
|
|
33
|
+
def configure
|
|
34
|
+
yield self
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.report(error=nil)
|
|
39
|
+
error = handle_exception(error)
|
|
40
|
+
yield if block_given? and error.nil?
|
|
41
|
+
rescue Exception => exception
|
|
42
|
+
error = handle_exception(exception)
|
|
43
|
+
ensure
|
|
44
|
+
post_report(error) unless error.nil?
|
|
45
|
+
raise exception unless exception.nil?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.handle_exception(exception)
|
|
49
|
+
return exception if exception.nil?
|
|
50
|
+
return exception if exception.is_a? ErrorReporter::Error
|
|
51
|
+
return nil unless reportable_exceptions.any? {|c| exception.is_a? c }
|
|
52
|
+
return nil if ignored_exceptions.any? {|c| exception.is_a? c }
|
|
53
|
+
Error.new(exception)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def self.post_report(error)
|
|
57
|
+
params = error.to_param
|
|
58
|
+
params[:report][:project] = { :api_token => api_token }
|
|
59
|
+
self.post('/reports.xml', :body => params)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
module ErrorReporter
|
|
3
|
+
module Adapters
|
|
4
|
+
|
|
5
|
+
module Rails
|
|
6
|
+
|
|
7
|
+
IGNORED_EXCEPTIONS = [ActiveRecord::RecordNotFound,
|
|
8
|
+
ActionController::RoutingError,
|
|
9
|
+
ActionController::InvalidAuthenticityToken,
|
|
10
|
+
CGI::Session::CookieStore::TamperedWithCookie]
|
|
11
|
+
|
|
12
|
+
def self.included(target)
|
|
13
|
+
target.send :alias_method_chain, :rescue_action_in_public, :errors
|
|
14
|
+
|
|
15
|
+
ErrorReporter.configure do |config|
|
|
16
|
+
config.ignored_exceptions IGNORED_EXCEPTIONS
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def rescue_action_in_public_with_errors(exception)
|
|
21
|
+
is_private = ::Rails.env.development? or ::Rails.env.test?
|
|
22
|
+
ErrorReporter.report(exception) unless is_private
|
|
23
|
+
rescue_action_in_public_without_errors(exception)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
::ActionController::Base.send :include, ErrorReporter::Adapters::Rails
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
module ErrorReporter
|
|
3
|
+
class Error
|
|
4
|
+
|
|
5
|
+
attr_accessor :hash_string
|
|
6
|
+
attr_accessor :name
|
|
7
|
+
attr_accessor :description
|
|
8
|
+
attr_accessor :properties
|
|
9
|
+
attr_accessor :backtrace
|
|
10
|
+
attr_accessor :environment
|
|
11
|
+
|
|
12
|
+
def initialize(exception)
|
|
13
|
+
self.name = "#{exception.class} #{exception.message}"
|
|
14
|
+
self.description = exception.message
|
|
15
|
+
self.backtrace = exception.backtrace.join("\n")
|
|
16
|
+
self.environment = { :application => $0 }
|
|
17
|
+
self.hash_string = Digest::SHA1.hexdigest(
|
|
18
|
+
[exception.class, exception.message, exception.backtrace.first].join('--')
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_param
|
|
23
|
+
{ :report =>
|
|
24
|
+
{ :error => {
|
|
25
|
+
:hash_string => self.hash_string
|
|
26
|
+
},:occurence => {
|
|
27
|
+
:name => self.name,
|
|
28
|
+
:description => self.description,
|
|
29
|
+
:backtrace => self.backtrace,
|
|
30
|
+
:properties => self.environment
|
|
31
|
+
} }
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
data/rails/init.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
describe "ErrorReporter" do
|
|
3
|
+
|
|
4
|
+
it "should send error reports" do
|
|
5
|
+
ErrorReporter.should_receive(:post).with('/reports.xml', an_instance_of(Hash))
|
|
6
|
+
lambda do
|
|
7
|
+
ErrorReporter.report do
|
|
8
|
+
raise "hello"
|
|
9
|
+
end
|
|
10
|
+
end.should raise_error(RuntimeError, "hello")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "should send error reports for selected exceptions" do
|
|
14
|
+
ErrorReporter.should_receive(:post).with('/reports.xml', an_instance_of(Hash))
|
|
15
|
+
ErrorReporter.reportable_exceptions ArgumentError
|
|
16
|
+
lambda do
|
|
17
|
+
ErrorReporter.report do
|
|
18
|
+
raise ArgumentError, "hello"
|
|
19
|
+
end
|
|
20
|
+
end.should raise_error(ArgumentError, "hello")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "should not send error reports for non-selected exceptions" do
|
|
24
|
+
ErrorReporter.should_not_receive(:post)
|
|
25
|
+
ErrorReporter.reportable_exceptions ArgumentError
|
|
26
|
+
lambda do
|
|
27
|
+
ErrorReporter.report do
|
|
28
|
+
raise RuntimeError, "hello"
|
|
29
|
+
end
|
|
30
|
+
end.should raise_error(RuntimeError, "hello")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
data/spec/error_spec.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
require File.dirname(__FILE__)+'/../lib/failtale_reporter'
|
|
3
|
+
|
|
4
|
+
describe "ErrorReporter::Error" do
|
|
5
|
+
|
|
6
|
+
describe "#to_param" do
|
|
7
|
+
|
|
8
|
+
it "should generate valid data" do
|
|
9
|
+
begin
|
|
10
|
+
raise "hello"
|
|
11
|
+
rescue Exception => exception
|
|
12
|
+
error = ErrorReporter::Error.new(exception)
|
|
13
|
+
|
|
14
|
+
error.backtrace.should be_eql(exception.backtrace.join("\n"))
|
|
15
|
+
error.description.should be_eql(exception.message)
|
|
16
|
+
error.name.should be_eql("#{exception.class} raised at #{exception.backtrace.first}")
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mrhenry-failtale-reporter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Simon Menke
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-01-30 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: httparty
|
|
17
|
+
version_requirement:
|
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
19
|
+
requirements:
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 0.2.6
|
|
23
|
+
version:
|
|
24
|
+
- !ruby/object:Gem::Dependency
|
|
25
|
+
name: httparty
|
|
26
|
+
version_requirement:
|
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
28
|
+
requirements:
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: 0.2.6
|
|
32
|
+
version:
|
|
33
|
+
description:
|
|
34
|
+
email: simon.menke@gmail.com
|
|
35
|
+
executables: []
|
|
36
|
+
|
|
37
|
+
extensions: []
|
|
38
|
+
|
|
39
|
+
extra_rdoc_files: []
|
|
40
|
+
|
|
41
|
+
files:
|
|
42
|
+
- rails/init.rb
|
|
43
|
+
- spec/error_reporter_spec.rb
|
|
44
|
+
- spec/error_spec.rb
|
|
45
|
+
- README.textile
|
|
46
|
+
- lib/failtale-reporter.rb
|
|
47
|
+
- lib/failtale_reporter/adapters/rails.rb
|
|
48
|
+
- lib/failtale_reporter/error.rb
|
|
49
|
+
- lib/failtale_reporter.rb
|
|
50
|
+
- lib/mrhenry-failtale-reporter.rb
|
|
51
|
+
has_rdoc: false
|
|
52
|
+
homepage: http://github.com/mrhenry
|
|
53
|
+
post_install_message:
|
|
54
|
+
rdoc_options: []
|
|
55
|
+
|
|
56
|
+
require_paths:
|
|
57
|
+
- lib
|
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: "0"
|
|
63
|
+
version:
|
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: "0"
|
|
69
|
+
version:
|
|
70
|
+
requirements: []
|
|
71
|
+
|
|
72
|
+
rubyforge_project: failtale-reporter
|
|
73
|
+
rubygems_version: 1.2.0
|
|
74
|
+
signing_key:
|
|
75
|
+
specification_version: 2
|
|
76
|
+
summary: A Ruby error reporter for our failtale service
|
|
77
|
+
test_files:
|
|
78
|
+
- spec/error_reporter_spec.rb
|
|
79
|
+
- spec/error_spec.rb
|
|
80
|
+
- spec/error_reporter_spec.rb
|
|
81
|
+
- spec/error_spec.rb
|