errornot_notifier 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/INSTALL +8 -8
- data/README.rdoc +63 -53
- data/Rakefile +92 -8
- data/TESTING.rdoc +1 -1
- data/generators/{hoptoad/hoptoad_generator.rb → errornot/errornot_generator.rb} +6 -6
- data/generators/{hoptoad → errornot}/lib/insert_commands.rb +0 -0
- data/generators/{hoptoad → errornot}/lib/rake_commands.rb +0 -0
- data/generators/errornot/templates/capistrano_hook.rb +6 -0
- data/generators/errornot/templates/errornot_notifier_tasks.rake +5 -0
- data/generators/{hoptoad → errornot}/templates/initializer.rb +2 -2
- data/lib/{hoptoad_notifier → errornot_notifier}/backtrace.rb +1 -1
- data/lib/errornot_notifier/capistrano.rb +20 -0
- data/lib/{hoptoad_notifier → errornot_notifier}/configuration.rb +14 -16
- data/lib/{hoptoad_notifier → errornot_notifier}/notice.rb +2 -2
- data/lib/{hoptoad_notifier → errornot_notifier}/rack.rb +8 -8
- data/lib/{hoptoad_notifier → errornot_notifier}/rails/action_controller_catcher.rb +9 -9
- data/lib/{hoptoad_notifier → errornot_notifier}/rails/controller_methods.rb +15 -15
- data/lib/{hoptoad_notifier → errornot_notifier}/rails/error_lookup.rb +9 -9
- data/lib/{hoptoad_notifier → errornot_notifier}/rails.rb +11 -11
- data/lib/{hoptoad_notifier → errornot_notifier}/sender.rb +8 -8
- data/lib/{hoptoad_notifier → errornot_notifier}/tasks.rb +19 -19
- data/lib/errornot_notifier/version.rb +3 -0
- data/lib/{hoptoad_notifier.rb → errornot_notifier.rb} +20 -20
- data/lib/{hoptoad_tasks.rb → errornot_tasks.rb} +9 -7
- data/lib/templates/rescue.erb +5 -5
- data/rails/init.rb +1 -1
- data/script/integration_test.rb +6 -6
- data/test/backtrace_test.rb +16 -16
- data/test/catcher_test.rb +22 -22
- data/test/configuration_test.rb +21 -23
- data/test/erronot_tasks_test.rb +147 -0
- data/test/helper.rb +16 -15
- data/test/logger_test.rb +12 -10
- data/test/notice_test.rb +9 -9
- data/test/notifier_test.rb +30 -30
- data/test/rack_test.rb +7 -7
- data/test/rails_initializer_test.rb +8 -8
- data/test/sender_test.rb +13 -12
- metadata +73 -53
- data/generators/hoptoad/templates/capistrano_hook.rb +0 -6
- data/generators/hoptoad/templates/hoptoad_notifier_tasks.rake +0 -5
- data/lib/hoptoad_notifier/capistrano.rb +0 -20
- data/lib/hoptoad_notifier/version.rb +0 -3
- data/test/hoptoad_tasks_test.rb +0 -138
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ErrornotNotifier
|
2
2
|
# Used to set up and modify settings for the notifier.
|
3
3
|
class Configuration
|
4
4
|
|
@@ -12,11 +12,11 @@ module HoptoadNotifier
|
|
12
12
|
# The API key for your project, found on the project edit form.
|
13
13
|
attr_accessor :api_key
|
14
14
|
|
15
|
-
# The host to connect
|
15
|
+
# The host to connect, there are no default value
|
16
16
|
attr_accessor :host
|
17
17
|
|
18
|
-
# The port on which your
|
19
|
-
#
|
18
|
+
# The port on which your Errornot server runs we can advise to
|
19
|
+
# prefere 443 for a secure connection
|
20
20
|
attr_accessor :port
|
21
21
|
|
22
22
|
# +true+ for https connections, +false+ for http connections.
|
@@ -40,7 +40,7 @@ module HoptoadNotifier
|
|
40
40
|
# The password to use when logging into your proxy server (if using a proxy)
|
41
41
|
attr_accessor :proxy_pass
|
42
42
|
|
43
|
-
# A list of parameters that should be filtered out of what is sent to
|
43
|
+
# A list of parameters that should be filtered out of what is sent to Errornot.
|
44
44
|
# By default, all "password" attributes will have their contents replaced.
|
45
45
|
attr_reader :params_filters
|
46
46
|
|
@@ -68,7 +68,7 @@ module HoptoadNotifier
|
|
68
68
|
# The path to the project in which the error occurred, such as the RAILS_ROOT
|
69
69
|
attr_accessor :project_root
|
70
70
|
|
71
|
-
# The name of the notifier library being used to send notifications (such as "
|
71
|
+
# The name of the notifier library being used to send notifications (such as "Errornot Notifier")
|
72
72
|
attr_accessor :notifier_name
|
73
73
|
|
74
74
|
# The version of the notifier library being used to send notifications (such as "1.0.2")
|
@@ -77,18 +77,18 @@ module HoptoadNotifier
|
|
77
77
|
# The url of the notifier library being used to send notifications
|
78
78
|
attr_accessor :notifier_url
|
79
79
|
|
80
|
-
# The logger used by
|
80
|
+
# The logger used by ErrornotNotifier
|
81
81
|
attr_accessor :logger
|
82
82
|
|
83
|
-
# The framework
|
83
|
+
# The framework ErrornotNotifier is configured to use
|
84
84
|
attr_accessor :framework
|
85
85
|
|
86
86
|
DEFAULT_PARAMS_FILTERS = %w(password password_confirmation).freeze
|
87
87
|
|
88
88
|
DEFAULT_BACKTRACE_FILTERS = [
|
89
89
|
lambda { |line|
|
90
|
-
if defined?(
|
91
|
-
line.gsub(/#{
|
90
|
+
if defined?(ErrornotNotifier.configuration.project_root) && ErrornotNotifier.configuration.project_root.to_s != ''
|
91
|
+
line.gsub(/#{ErrornotNotifier.configuration.project_root}/, "[PROJECT_ROOT]")
|
92
92
|
else
|
93
93
|
line
|
94
94
|
end
|
@@ -101,7 +101,7 @@ module HoptoadNotifier
|
|
101
101
|
end
|
102
102
|
end
|
103
103
|
},
|
104
|
-
lambda { |line| line if line !~ %r{lib/
|
104
|
+
lambda { |line| line if line !~ %r{lib/errornot_notifier} }
|
105
105
|
].freeze
|
106
106
|
|
107
107
|
IGNORE_DEFAULT = ['ActiveRecord::RecordNotFound',
|
@@ -114,7 +114,6 @@ module HoptoadNotifier
|
|
114
114
|
|
115
115
|
def initialize
|
116
116
|
@secure = false
|
117
|
-
@host = 'hoptoadapp.com'
|
118
117
|
@http_open_timeout = 2
|
119
118
|
@http_read_timeout = 5
|
120
119
|
@params_filters = DEFAULT_PARAMS_FILTERS.dup
|
@@ -124,9 +123,8 @@ module HoptoadNotifier
|
|
124
123
|
@ignore_user_agent = []
|
125
124
|
@development_environments = %w(development test cucumber)
|
126
125
|
@development_lookup = true
|
127
|
-
@notifier_name = '
|
126
|
+
@notifier_name = 'Errornot Notifier'
|
128
127
|
@notifier_version = VERSION
|
129
|
-
@notifier_url = 'http://hoptoadapp.com'
|
130
128
|
@framework = 'Standalone'
|
131
129
|
end
|
132
130
|
|
@@ -153,8 +151,8 @@ module HoptoadNotifier
|
|
153
151
|
# end
|
154
152
|
#
|
155
153
|
# @param [Proc] block The new ignore filter
|
156
|
-
# @yieldparam [Hash] data The exception data given to +
|
157
|
-
# @yieldreturn [Boolean] If the block returns true the exception will be ignored, otherwise it will be processed by
|
154
|
+
# @yieldparam [Hash] data The exception data given to +ErrornotNotifier.notify+
|
155
|
+
# @yieldreturn [Boolean] If the block returns true the exception will be ignored, otherwise it will be processed by Errornot.
|
158
156
|
def ignore_by_filter(&block)
|
159
157
|
self.ignore_by_filters << block
|
160
158
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module ErrornotNotifier
|
2
2
|
class Notice
|
3
3
|
|
4
4
|
# The exception that caused this notice, if any
|
@@ -54,7 +54,7 @@ module HoptoadNotifier
|
|
54
54
|
# See Configuration#ignore_by_filters
|
55
55
|
attr_reader :ignore_by_filters
|
56
56
|
|
57
|
-
# The name of the notifier library sending this notice, such as "
|
57
|
+
# The name of the notifier library sending this notice, such as "Errornot Notifier"
|
58
58
|
attr_reader :notifier_name
|
59
59
|
|
60
60
|
# The version number of the notifier library sending this notice, such as "2.1.3"
|
@@ -1,22 +1,22 @@
|
|
1
|
-
module
|
1
|
+
module ErrornotNotifier
|
2
2
|
# Middleware for Rack applications. Any errors raised by the upstream
|
3
|
-
# application will be delivered to
|
3
|
+
# application will be delivered to Errornot and re-raised.
|
4
4
|
#
|
5
5
|
# Synopsis:
|
6
6
|
#
|
7
7
|
# require 'rack'
|
8
|
-
# require '
|
8
|
+
# require 'errornot_notifier'
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# ErrornotNotifier.configure do |config|
|
11
11
|
# config.api_key = 'my_api_key'
|
12
12
|
# end
|
13
13
|
#
|
14
14
|
# app = Rack::Builder.app do
|
15
|
-
# use
|
15
|
+
# use ErrornotNotifier::Rack
|
16
16
|
# run lambda { |env| raise "Rack down" }
|
17
17
|
# end
|
18
18
|
#
|
19
|
-
# Use a standard
|
19
|
+
# Use a standard ErrornotNotifier.configure call to configure your api key.
|
20
20
|
class Rack
|
21
21
|
def initialize(app)
|
22
22
|
@app = app
|
@@ -26,12 +26,12 @@ module HoptoadNotifier
|
|
26
26
|
begin
|
27
27
|
response = @app.call(env)
|
28
28
|
rescue Exception => raised
|
29
|
-
|
29
|
+
ErrornotNotifier.notify_or_ignore(raised, :rack_env => env)
|
30
30
|
raise
|
31
31
|
end
|
32
32
|
|
33
33
|
if env['rack.exception']
|
34
|
-
|
34
|
+
ErrornotNotifier.notify_or_ignore(env['rack.exception'], :rack_env => env)
|
35
35
|
end
|
36
36
|
|
37
37
|
response
|
@@ -1,28 +1,28 @@
|
|
1
|
-
module
|
1
|
+
module ErrornotNotifier
|
2
2
|
module Rails
|
3
3
|
module ActionControllerCatcher
|
4
4
|
|
5
5
|
# Sets up an alias chain to catch exceptions when Rails does
|
6
6
|
def self.included(base) #:nodoc:
|
7
|
-
base.send(:alias_method, :
|
8
|
-
base.send(:alias_method, :rescue_action_in_public, :
|
7
|
+
base.send(:alias_method, :rescue_action_in_public_without_errornot, :rescue_action_in_public)
|
8
|
+
base.send(:alias_method, :rescue_action_in_public, :rescue_action_in_public_with_errornot)
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
13
|
# Overrides the rescue_action method in ActionController::Base, but does not inhibit
|
14
14
|
# any custom processing that is defined with Rails 2's exception helpers.
|
15
|
-
def
|
16
|
-
unless
|
17
|
-
|
15
|
+
def rescue_action_in_public_with_errornot(exception)
|
16
|
+
unless errornot_ignore_user_agent?
|
17
|
+
ErrornotNotifier.notify_or_ignore(exception, errornot_request_data)
|
18
18
|
end
|
19
|
-
|
19
|
+
rescue_action_in_public_without_errornot(exception)
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def errornot_ignore_user_agent? #:nodoc:
|
23
23
|
# Rails 1.2.6 doesn't have request.user_agent, so check for it here
|
24
24
|
user_agent = request.respond_to?(:user_agent) ? request.user_agent : request.env["HTTP_USER_AGENT"]
|
25
|
-
|
25
|
+
ErrornotNotifier.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -1,33 +1,33 @@
|
|
1
|
-
module
|
1
|
+
module ErrornotNotifier
|
2
2
|
module Rails
|
3
3
|
module ControllerMethods
|
4
4
|
private
|
5
5
|
|
6
6
|
# This method should be used for sending manual notifications while you are still
|
7
|
-
# inside the controller. Otherwise it works like
|
8
|
-
def
|
7
|
+
# inside the controller. Otherwise it works like ErrornotNotifier.notify.
|
8
|
+
def notify_errornot(hash_or_exception)
|
9
9
|
unless consider_all_requests_local || local_request?
|
10
|
-
|
10
|
+
ErrornotNotifier.notify(hash_or_exception, errornot_request_data)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def errornot_ignore_user_agent? #:nodoc:
|
15
15
|
# Rails 1.2.6 doesn't have request.user_agent, so check for it here
|
16
16
|
user_agent = request.respond_to?(:user_agent) ? request.user_agent : request.env["HTTP_USER_AGENT"]
|
17
|
-
|
17
|
+
ErrornotNotifier.configuration.ignore_user_agent.flatten.any? { |ua| ua === user_agent }
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
21
|
-
{ :parameters =>
|
22
|
-
:session_data =>
|
20
|
+
def errornot_request_data
|
21
|
+
{ :parameters => errornot_filter_if_filtering(params.to_hash),
|
22
|
+
:session_data => errornot_session_data,
|
23
23
|
:controller => params[:controller],
|
24
24
|
:action => params[:action],
|
25
|
-
:url =>
|
26
|
-
:cgi_data =>
|
27
|
-
:environment_vars =>
|
25
|
+
:url => errornot_request_url,
|
26
|
+
:cgi_data => errornot_filter_if_filtering(request.env),
|
27
|
+
:environment_vars => errornot_filter_if_filtering(ENV) }
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
30
|
+
def errornot_filter_if_filtering(hash)
|
31
31
|
if respond_to?(:filter_parameters)
|
32
32
|
filter_parameters(hash) rescue hash
|
33
33
|
else
|
@@ -35,7 +35,7 @@ module HoptoadNotifier
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
def
|
38
|
+
def errornot_session_data
|
39
39
|
if session.respond_to?(:to_hash)
|
40
40
|
session.to_hash
|
41
41
|
else
|
@@ -43,7 +43,7 @@ module HoptoadNotifier
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
46
|
+
def errornot_request_url
|
47
47
|
url = "#{request.protocol}#{request.host}"
|
48
48
|
|
49
49
|
unless [80, 443].include?(request.port)
|
@@ -1,27 +1,27 @@
|
|
1
|
-
module
|
1
|
+
module ErrornotNotifier
|
2
2
|
module Rails
|
3
3
|
module ErrorLookup
|
4
4
|
|
5
5
|
# Sets up an alias chain to catch exceptions when Rails does
|
6
6
|
def self.included(base) #:nodoc:
|
7
|
-
base.send(:alias_method, :
|
8
|
-
base.send(:alias_method, :rescue_action_locally, :
|
7
|
+
base.send(:alias_method, :rescue_action_locally_without_errornot, :rescue_action_locally)
|
8
|
+
base.send(:alias_method, :rescue_action_locally, :rescue_action_locally_with_errornot)
|
9
9
|
end
|
10
10
|
|
11
11
|
private
|
12
12
|
|
13
|
-
def
|
14
|
-
result =
|
13
|
+
def rescue_action_locally_with_errornot(exception)
|
14
|
+
result = rescue_action_locally_without_errornot(exception)
|
15
15
|
|
16
|
-
if
|
16
|
+
if ErrornotNotifier.configuration.development_lookup
|
17
17
|
path = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'rescue.erb')
|
18
|
-
notice =
|
18
|
+
notice = ErrornotNotifier.build_lookup_hash_for(exception, errornot_request_data)
|
19
19
|
|
20
20
|
result << @template.render(
|
21
21
|
:file => path,
|
22
22
|
:use_full_path => false,
|
23
|
-
:locals => { :host =>
|
24
|
-
:api_key =>
|
23
|
+
:locals => { :host => ErrornotNotifier.configuration.host,
|
24
|
+
:api_key => ErrornotNotifier.configuration.api_key,
|
25
25
|
:notice => notice })
|
26
26
|
end
|
27
27
|
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
1
|
+
require 'errornot_notifier'
|
2
|
+
require 'errornot_notifier/rails/controller_methods'
|
3
|
+
require 'errornot_notifier/rails/action_controller_catcher'
|
4
|
+
require 'errornot_notifier/rails/error_lookup'
|
5
5
|
|
6
|
-
module
|
6
|
+
module ErrornotNotifier
|
7
7
|
module Rails
|
8
8
|
def self.initialize
|
9
9
|
if defined?(ActionController::Base)
|
10
|
-
ActionController::Base.send(:include,
|
11
|
-
ActionController::Base.send(:include,
|
12
|
-
ActionController::Base.send(:include,
|
10
|
+
ActionController::Base.send(:include, ErrornotNotifier::Rails::ActionControllerCatcher)
|
11
|
+
ActionController::Base.send(:include, ErrornotNotifier::Rails::ErrorLookup)
|
12
|
+
ActionController::Base.send(:include, ErrornotNotifier::Rails::ControllerMethods)
|
13
13
|
end
|
14
14
|
|
15
15
|
rails_logger = if defined?(::Rails.logger)
|
@@ -20,10 +20,10 @@ module HoptoadNotifier
|
|
20
20
|
|
21
21
|
if defined?(::Rails.configuration) && ::Rails.configuration.respond_to?(:middleware)
|
22
22
|
::Rails.configuration.middleware.insert_after 'ActionController::Failsafe',
|
23
|
-
|
23
|
+
ErrornotNotifier::Rack
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
ErrornotNotifier.configure(true) do |config|
|
27
27
|
config.logger = rails_logger
|
28
28
|
config.environment_name = RAILS_ENV if defined?(RAILS_ENV)
|
29
29
|
config.project_root = RAILS_ROOT if defined?(RAILS_ROOT)
|
@@ -33,5 +33,5 @@ module HoptoadNotifier
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
ErrornotNotifier::Rails.initialize
|
37
37
|
|
@@ -1,5 +1,5 @@
|
|
1
|
-
module
|
2
|
-
# Sends out the notice to
|
1
|
+
module ErrornotNotifier
|
2
|
+
# Sends out the notice to Errornot
|
3
3
|
class Sender
|
4
4
|
|
5
5
|
NOTICES_URI = '/errors'.freeze
|
@@ -30,10 +30,10 @@ module HoptoadNotifier
|
|
30
30
|
end
|
31
31
|
|
32
32
|
|
33
|
-
# Sends the notice data off to
|
33
|
+
# Sends the notice data off to Errornot for processing.
|
34
34
|
#
|
35
35
|
# @param [String] data The XML notice to be sent off
|
36
|
-
def
|
36
|
+
def send_to_errornot(data)
|
37
37
|
logger.debug { "Sending request to #{url.to_s}:\n#{data}" } if logger
|
38
38
|
|
39
39
|
http =
|
@@ -50,7 +50,7 @@ module HoptoadNotifier
|
|
50
50
|
data = process_payload(data)
|
51
51
|
http.post(url.path, data, HEADERS)
|
52
52
|
rescue TimeoutError => e
|
53
|
-
log :error, "Timeout while contacting the
|
53
|
+
log :error, "Timeout while contacting the Errornot server."
|
54
54
|
nil
|
55
55
|
end
|
56
56
|
|
@@ -73,12 +73,12 @@ module HoptoadNotifier
|
|
73
73
|
|
74
74
|
def log(level, message, response = nil)
|
75
75
|
logger.send level, LOG_PREFIX + message if logger
|
76
|
-
|
77
|
-
|
76
|
+
ErrornotNotifier.report_environment_info
|
77
|
+
ErrornotNotifier.report_response_body(response.body) if response && response.respond_to?(:body)
|
78
78
|
end
|
79
79
|
|
80
80
|
def logger
|
81
|
-
|
81
|
+
ErrornotNotifier.logger
|
82
82
|
end
|
83
83
|
|
84
84
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'errornot_notifier'
|
2
2
|
|
3
|
-
namespace :
|
4
|
-
desc "Notify
|
3
|
+
namespace :errornot do
|
4
|
+
desc "Notify Errornot of a new deploy."
|
5
5
|
task :deploy => :environment do
|
6
|
-
require '
|
7
|
-
|
6
|
+
require 'errornot_tasks'
|
7
|
+
ErrornotTasks.deploy(:rails_env => ENV['TO'],
|
8
8
|
:scm_revision => ENV['REVISION'],
|
9
9
|
:scm_repository => ENV['REPO'],
|
10
10
|
:local_username => ENV['USER'],
|
@@ -16,24 +16,24 @@ namespace :hoptoad do
|
|
16
16
|
RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
|
17
17
|
end
|
18
18
|
|
19
|
-
desc "Verify your gem installation by sending a test exception to the
|
20
|
-
task :test => ['
|
19
|
+
desc "Verify your gem installation by sending a test exception to the errornot service"
|
20
|
+
task :test => ['errornot:log_stdout', :environment] do
|
21
21
|
RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
|
22
22
|
|
23
23
|
require 'action_controller/test_process'
|
24
24
|
|
25
25
|
Dir["app/controllers/application*.rb"].each { |file| require(file) }
|
26
26
|
|
27
|
-
class
|
27
|
+
class ErrornotTestingException < RuntimeError; end
|
28
28
|
|
29
|
-
unless
|
30
|
-
puts "
|
29
|
+
unless ErrornotNotifier.configuration.api_key
|
30
|
+
puts "Errornot needs an API key configured! Check the README to see how to add it."
|
31
31
|
exit
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
ErrornotNotifier.configuration.development_environments = []
|
35
35
|
|
36
|
-
catcher =
|
36
|
+
catcher = ErrornotNotifier::Rails::ActionControllerCatcher
|
37
37
|
in_controller = ApplicationController.included_modules.include?(catcher)
|
38
38
|
in_base = ActionController::Base.included_modules.include?(catcher)
|
39
39
|
if !in_controller || !in_base
|
@@ -42,7 +42,7 @@ namespace :hoptoad do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
puts "Configuration:"
|
45
|
-
|
45
|
+
ErrornotNotifier.configuration.to_hash.each do |key, value|
|
46
46
|
puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
|
47
47
|
end
|
48
48
|
|
@@ -54,10 +54,10 @@ namespace :hoptoad do
|
|
54
54
|
puts 'Setting up the Controller.'
|
55
55
|
class ApplicationController
|
56
56
|
# This is to bypass any filters that may prevent access to the action.
|
57
|
-
prepend_before_filter :
|
58
|
-
def
|
57
|
+
prepend_before_filter :test_errornot
|
58
|
+
def test_errornot
|
59
59
|
puts "Raising '#{exception_class.name}' to simulate application failure."
|
60
|
-
raise exception_class.new, 'Testing
|
60
|
+
raise exception_class.new, 'Testing errornot via "rake errornot:test". If you can see this, it works.'
|
61
61
|
end
|
62
62
|
|
63
63
|
def rescue_action(exception)
|
@@ -76,7 +76,7 @@ namespace :hoptoad do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def exception_class
|
79
|
-
exception_name = ENV['EXCEPTION'] || "
|
79
|
+
exception_name = ENV['EXCEPTION'] || "ErrornotTestingException"
|
80
80
|
Object.const_get(exception_name)
|
81
81
|
rescue
|
82
82
|
Object.const_set(exception_name, Class.new(Exception))
|
@@ -86,12 +86,12 @@ namespace :hoptoad do
|
|
86
86
|
nil
|
87
87
|
end
|
88
88
|
end
|
89
|
-
class
|
89
|
+
class ErrornotVerificationController < ApplicationController; end
|
90
90
|
|
91
91
|
puts 'Processing request.'
|
92
92
|
request = ActionController::TestRequest.new
|
93
93
|
response = ActionController::TestResponse.new
|
94
|
-
|
94
|
+
ErrornotVerificationController.new.process(request, response)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -2,15 +2,15 @@ require 'net/http'
|
|
2
2
|
require 'net/https'
|
3
3
|
require 'rubygems'
|
4
4
|
require 'active_support'
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require '
|
5
|
+
require 'errornot_notifier/version'
|
6
|
+
require 'errornot_notifier/configuration'
|
7
|
+
require 'errornot_notifier/notice'
|
8
|
+
require 'errornot_notifier/sender'
|
9
|
+
require 'errornot_notifier/backtrace'
|
10
|
+
require 'errornot_notifier/rack'
|
11
11
|
|
12
|
-
# Gem for applications to automatically post errors to the
|
13
|
-
module
|
12
|
+
# Gem for applications to automatically post errors to the Errornot of their choice.
|
13
|
+
module ErrornotNotifier
|
14
14
|
|
15
15
|
API_VERSION = "1.0"
|
16
16
|
LOG_PREFIX = "** [ErrorNot Logger] "
|
@@ -21,12 +21,12 @@ module HoptoadNotifier
|
|
21
21
|
}
|
22
22
|
|
23
23
|
class << self
|
24
|
-
# The sender object is responsible for delivering formatted data to the
|
25
|
-
# Must respond to #
|
24
|
+
# The sender object is responsible for delivering formatted data to the Errornot server.
|
25
|
+
# Must respond to #send_to_errornot. See ErrornotNotifier::Sender.
|
26
26
|
attr_accessor :sender
|
27
27
|
|
28
|
-
# A
|
29
|
-
# values for all
|
28
|
+
# A Errornot configuration object. Must act like a hash and return sensible
|
29
|
+
# values for all Errornot configuration options. See ErrornotNotifier::Configuration.
|
30
30
|
attr_accessor :configuration
|
31
31
|
|
32
32
|
# Tell the log that the Notifier is good to go
|
@@ -39,9 +39,9 @@ module HoptoadNotifier
|
|
39
39
|
write_verbose_log("Environment Info: #{environment_info}")
|
40
40
|
end
|
41
41
|
|
42
|
-
# Prints out the response body from
|
42
|
+
# Prints out the response body from Errornot for debugging help
|
43
43
|
def report_response_body(response)
|
44
|
-
write_verbose_log("Response from
|
44
|
+
write_verbose_log("Response from Errornot: \n#{response}")
|
45
45
|
end
|
46
46
|
|
47
47
|
# Returns the Ruby version, Rails version, and current Rails environment
|
@@ -64,7 +64,7 @@ module HoptoadNotifier
|
|
64
64
|
# Call this method to modify defaults in your initializers.
|
65
65
|
#
|
66
66
|
# @example
|
67
|
-
#
|
67
|
+
# ErrornotNotifier.configure do |config|
|
68
68
|
# config.api_key = '1234567890abcdef'
|
69
69
|
# config.secure = false
|
70
70
|
# end
|
@@ -77,10 +77,10 @@ module HoptoadNotifier
|
|
77
77
|
|
78
78
|
# Sends an exception manually using this method, even when you are not in a controller.
|
79
79
|
#
|
80
|
-
# @param [Exception] exception The exception you want to notify
|
81
|
-
# @param [Hash] opts Data that will be sent to
|
80
|
+
# @param [Exception] exception The exception you want to notify Errornot about.
|
81
|
+
# @param [Hash] opts Data that will be sent to Errornot.
|
82
82
|
#
|
83
|
-
# @option opts [String] :api_key The API key for this project. The API key is a unique identifier that
|
83
|
+
# @option opts [String] :api_key The API key for this project. The API key is a unique identifier that Errornot uses for identification.
|
84
84
|
# @option opts [String] :error_message The error returned by the exception (or the message you want to log).
|
85
85
|
# @option opts [String] :backtrace A backtrace, usually obtained with +caller+.
|
86
86
|
# @option opts [String] :request The controller's request object.
|
@@ -91,7 +91,7 @@ module HoptoadNotifier
|
|
91
91
|
end
|
92
92
|
|
93
93
|
# Sends the notice unless it is one of the default ignored exceptions
|
94
|
-
# @see
|
94
|
+
# @see ErrornotNotifier.notify
|
95
95
|
def notify_or_ignore(exception, opts = {})
|
96
96
|
notice = build_notice_for(exception, opts)
|
97
97
|
send_notice(notice) unless notice.ignore?
|
@@ -118,7 +118,7 @@ module HoptoadNotifier
|
|
118
118
|
|
119
119
|
def send_notice(notice)
|
120
120
|
if configuration.public?
|
121
|
-
sender.
|
121
|
+
sender.send_to_errornot(notice.to_xml)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -2,19 +2,21 @@ require 'net/http'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'active_support'
|
4
4
|
|
5
|
-
# Capistrano tasks for notifying
|
6
|
-
module
|
5
|
+
# Capistrano tasks for notifying Errornot of deploys
|
6
|
+
module ErrornotTasks
|
7
7
|
|
8
|
-
# Alerts
|
8
|
+
# Alerts Errornot of a deploy.
|
9
9
|
#
|
10
|
-
# @param [Hash] opts Data about the deploy that is set to
|
10
|
+
# @param [Hash] opts Data about the deploy that is set to Errornot
|
11
11
|
#
|
12
12
|
# @option opts [String] :rails_env Environment of the deploy (production, staging)
|
13
13
|
# @option opts [String] :scm_revision The given revision/sha that is being deployed
|
14
14
|
# @option opts [String] :scm_repository Address of your repository to help with code lookups
|
15
15
|
# @option opts [String] :local_username Who is deploying
|
16
16
|
def self.deploy(opts = {})
|
17
|
-
|
17
|
+
raise NotImplementedError.new("it's not implemented in errornot now")
|
18
|
+
# TODO: implement it in ErrorNot
|
19
|
+
if ErrornotNotifier.configuration.api_key.blank?
|
18
20
|
puts "I don't seem to be configured with an API key. Please check your configuration."
|
19
21
|
return false
|
20
22
|
end
|
@@ -25,10 +27,10 @@ module HoptoadTasks
|
|
25
27
|
end
|
26
28
|
|
27
29
|
params = {'api_key' => opts.delete(:api_key) ||
|
28
|
-
|
30
|
+
ErrornotNotifier.configuration.api_key}
|
29
31
|
opts.each {|k,v| params["deploy[#{k}]"] = v }
|
30
32
|
|
31
|
-
url = URI.parse("http://#{
|
33
|
+
url = URI.parse("http://#{ErrornotNotifier.configuration.host}/deploys")
|
32
34
|
response = Net::HTTP.post_form(url, params)
|
33
35
|
puts response.body
|
34
36
|
return Net::HTTPSuccess === response
|
data/lib/templates/rescue.erb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
<script type="text/javascript">
|
2
|
-
var
|
2
|
+
var Errornot = {
|
3
3
|
host : <%= host.to_json %>,
|
4
4
|
api_key : <%= api_key.to_json %>,
|
5
5
|
notice : <%= notice.to_json %>,
|
@@ -19,7 +19,7 @@ var Hoptoad = {
|
|
19
19
|
}
|
20
20
|
|
21
21
|
data[data.length] = 'notice[api_key]=' + this.api_key;
|
22
|
-
data[data.length] = 'callback=
|
22
|
+
data[data.length] = 'callback=Errornot.onSuccess';
|
23
23
|
data[data.length] = '_=' + (new Date()).getTime();
|
24
24
|
|
25
25
|
var head = document.getElementsByTagName('head')[0];
|
@@ -50,7 +50,7 @@ var Hoptoad = {
|
|
50
50
|
var text = document.createTextNode(this.message);
|
51
51
|
var element = document.createElement('a');
|
52
52
|
|
53
|
-
element.id = '
|
53
|
+
element.id = 'errornot';
|
54
54
|
element.href = 'http://' + error.subdomain + '.' + this.host +
|
55
55
|
'/projects/' + error.project_id + '/errors/' + error.id;
|
56
56
|
element.appendChild(text);
|
@@ -70,12 +70,12 @@ var Hoptoad = {
|
|
70
70
|
};
|
71
71
|
|
72
72
|
window.onload = function() {
|
73
|
-
|
73
|
+
Errornot.initialize.apply(Errornot);
|
74
74
|
};
|
75
75
|
</script>
|
76
76
|
|
77
77
|
<style type="text/css">
|
78
|
-
#
|
78
|
+
#errornot {
|
79
79
|
background: #FFF url(http://hoptoadapp.com/images/fell-off-the-toad.gif) no-repeat top right;
|
80
80
|
color: #F00;
|
81
81
|
padding: 45px 101px 45px 12px;
|