runtimeerror_notifier 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +1 -0
- data/LICENSE +34 -0
- data/README.md +23 -0
- data/lib/generators/runtimeerror_notifier/install_generator.rb +8 -0
- data/lib/generators/runtimeerror_notifier/templates/initializer.rb +10 -0
- data/lib/runtimeerror_notifier.rb +40 -0
- data/lib/runtimeerror_notifier/missing_controller.rb +3 -0
- data/lib/runtimeerror_notifier/notifier.rb +112 -0
- metadata +91 -0
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Change Log
|
data/LICENSE
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
All other components of this product are
|
2
|
+
Copyright (c) 2013 Devels Advocates. All rights reserved
|
3
|
+
|
4
|
+
Subject to the terms of this notice, Devels Advocates grants you a
|
5
|
+
nonexclusive, nontransferable license, without the right to
|
6
|
+
sublicense, to (a) install and execute one copy of these files on any
|
7
|
+
number of workstations owned or controlled by you and (b) distribute
|
8
|
+
verbatim copies of these files to third parties. As a condition to the
|
9
|
+
foregoing grant, you must provide this notice along with each copy you
|
10
|
+
distribute and you must not remove, alter, or obscure this notice. All
|
11
|
+
other use, reproduction, modification, distribution, or other
|
12
|
+
exploitation of these files is strictly prohibited, except as may be set
|
13
|
+
forth in a separate written license agreement between you and Devels Advocates.
|
14
|
+
The terms of any such license agreement will control over this
|
15
|
+
notice. The license stated above will be automatically terminated and
|
16
|
+
revoked if you exceed its scope or violate any of the terms of this
|
17
|
+
notice.
|
18
|
+
|
19
|
+
This License does not grant permission to use the trade names,
|
20
|
+
trademarks, service marks, or product names of RuntimeError.net, except as
|
21
|
+
required for reasonable and customary use in describing the origin of
|
22
|
+
this file and reproducing the content of this notice. You may not
|
23
|
+
mark or brand this file with any trade name, trademarks, service
|
24
|
+
marks, or product names other than the original brand (if any)
|
25
|
+
provided by Devels Advocates.
|
26
|
+
|
27
|
+
Unless otherwise expressly agreed by Devels Advocates in a separate written
|
28
|
+
license agreement, these files are provided AS IS, WITHOUT WARRANTY OF
|
29
|
+
ANY KIND, including without any implied warranties of MERCHANTABILITY,
|
30
|
+
FITNESS FOR A PARTICULAR PURPOSE, TITLE, or NON-INFRINGEMENT. As a
|
31
|
+
condition to your use of these files, you are solely responsible for
|
32
|
+
such use. Devels Advocates will have no liability to you for direct,
|
33
|
+
indirect, consequential, incidental, special, or punitive damages or
|
34
|
+
for lost profits or data.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# RuntimeError.net
|
2
|
+
|
3
|
+
This gem acts as the agent for [RuntimeError.net](http://runtimeerror.net). Install the gem for the agent to handle uncaught exceptions from your application.
|
4
|
+
|
5
|
+
## Installation (Rails 3)
|
6
|
+
|
7
|
+
**Step 1.** Add it as a gem in your __Gemfile__
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem 'runtimeerror_notifier', git: 'git://github.com/develsadvocates/exception_notification_http.git', branch: 'released-v0'
|
11
|
+
```
|
12
|
+
|
13
|
+
**Step 2.** Execute the following command to generate __config/initializers/runtimeerror_notifier.rb__
|
14
|
+
|
15
|
+
``` sh
|
16
|
+
RAILS_ENV=production rails generate runtimeerror_notifier:install
|
17
|
+
```
|
18
|
+
|
19
|
+
**Step 3.** Obtain a secret email address from [RuntimeError.net](http://runtimeerror.net) then set it as environment variable ``RUNTIMEERROR_EMAIL``
|
20
|
+
|
21
|
+
## License
|
22
|
+
|
23
|
+
© RuntimeError.net 2013. View LICENSE for details.
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class RuntimeerrorNotifier::InstallGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
desc 'Creates an initializer file for RuntimeError.net at config/initializers'
|
4
|
+
|
5
|
+
def install
|
6
|
+
template 'initializer.rb', 'config/initializers/runtimeerror_notifier.rb'
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
if defined?(RuntimeerrorNotifier)
|
2
|
+
# Get your secret email address from RuntimeError.net and
|
3
|
+
# 1. Set it as environment variable RUNTIMEERROR_EMAIL (preferred method)
|
4
|
+
# 2. OR, change the value (legacy method)
|
5
|
+
RuntimeerrorNotifier.for ENV['RUNTIMEERROR_EMAIL']
|
6
|
+
|
7
|
+
RuntimeerrorNotifier::Notifier::IGNORED_EXCEPTIONS.push(*%w[
|
8
|
+
ActionController::RoutingError
|
9
|
+
])
|
10
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'runtimeerror_notifier/notifier'
|
2
|
+
|
3
|
+
module RuntimeerrorNotifier
|
4
|
+
def self.for(*emails)
|
5
|
+
RuntimeerrorNotifier::Notifier.for(*emails)
|
6
|
+
if defined?(::Rails)
|
7
|
+
::Rails.application.config.middleware.insert 0, RuntimeerrorNotifier::Tracker
|
8
|
+
end
|
9
|
+
renderer_class = if defined?(::ActionDispatch::DebugExceptions)
|
10
|
+
::ActionDispatch::DebugExceptions
|
11
|
+
elsif defined?(::ActionDispatch::ShowExceptions)
|
12
|
+
::ActionDispatch::ShowExceptions
|
13
|
+
end
|
14
|
+
if renderer_class
|
15
|
+
renderer_class.class_eval do
|
16
|
+
def render_exception_with_runtimeerror_notifier(env, exception)
|
17
|
+
begin
|
18
|
+
RuntimeerrorNotifier::Notifier.notification(env, exception, {})
|
19
|
+
rescue Exception
|
20
|
+
# do nothing
|
21
|
+
end
|
22
|
+
render_exception_without_runtimeerror_notifier(env, exception)
|
23
|
+
end
|
24
|
+
alias_method_chain :render_exception, :runtimeerror_notifier
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
class Tracker
|
29
|
+
def initialize(app, options={})
|
30
|
+
@app, @options = app, options
|
31
|
+
end
|
32
|
+
|
33
|
+
def call(env)
|
34
|
+
@app.call(env)
|
35
|
+
rescue Exception => ex
|
36
|
+
RuntimeerrorNotifier::Notifier.notification(env, ex, @options)
|
37
|
+
raise ex
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'action_dispatch'
|
2
|
+
require 'action_mailer'
|
3
|
+
require 'pp'
|
4
|
+
require 'httparty'
|
5
|
+
require File.join(File.dirname(__FILE__), 'missing_controller')
|
6
|
+
|
7
|
+
module RuntimeerrorNotifier
|
8
|
+
class Notifier < ActionMailer::Base
|
9
|
+
API_ENDPOINT = ENV['RUNTIMEERROR_URL'] || 'http://runtimeerror.net/incoming_emails'
|
10
|
+
SENDER_ADDRESS = 'notifier@runtimeerror.net'
|
11
|
+
RECIPIENTS = []
|
12
|
+
SECTIONS = %w(request session environment backtrace)
|
13
|
+
TEMPLATE_NAME = 'runtimeerror_notifier'
|
14
|
+
IGNORED_EXCEPTIONS = []
|
15
|
+
|
16
|
+
self.mailer_name = 'runtimeerror_notifier'
|
17
|
+
self.append_view_path File.join(File.dirname(__FILE__), '..', '..', 'templates')
|
18
|
+
|
19
|
+
def self.for(*emails)
|
20
|
+
RECIPIENTS.push(*emails)
|
21
|
+
RECIPIENTS.uniq!
|
22
|
+
end
|
23
|
+
|
24
|
+
def notification(env, exception, options={})
|
25
|
+
original_exception = if exception.respond_to?(:original_exception)
|
26
|
+
exception.original_exception
|
27
|
+
elsif exception.respond_to?(:continued_exception)
|
28
|
+
exception.continued_exception
|
29
|
+
else
|
30
|
+
exception
|
31
|
+
end
|
32
|
+
case exception.class.name
|
33
|
+
when *IGNORED_EXCEPTIONS
|
34
|
+
# ignore
|
35
|
+
else
|
36
|
+
email = compose_email(env, original_exception, options)
|
37
|
+
make_request(email)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
def make_request(email)
|
44
|
+
HTTParty.post(API_ENDPOINT, body: {message: email.to_s})
|
45
|
+
end
|
46
|
+
|
47
|
+
def compose_email(env, exception, options)
|
48
|
+
@attr = exception_attributes(env, exception, options)
|
49
|
+
mail(:to => @attr[:recipients],
|
50
|
+
:from => @attr[:sender_address],
|
51
|
+
:subject => compose_subject(@attr),
|
52
|
+
:template_name => TEMPLATE_NAME) do |format|
|
53
|
+
format.html
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def exception_attributes(env, exception, options={})
|
58
|
+
{
|
59
|
+
env: env,
|
60
|
+
exception: exception,
|
61
|
+
api_endpoint: options[:api_endpoint] || API_ENDPOINT,
|
62
|
+
kontroller: env['action_controller.instance'] || MissingController.new,
|
63
|
+
request: ActionDispatch::Request.new(env),
|
64
|
+
backtrace: exception.backtrace ? clean_backtrace(exception) : [],
|
65
|
+
recipients: options[:recipients] || RECIPIENTS,
|
66
|
+
sender_address: options[:sender_address] || SENDER_ADDRESS,
|
67
|
+
sections: SECTIONS
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
def compose_subject(attr)
|
72
|
+
subject = ''
|
73
|
+
subject << formatted_controller_name(attr[:kontroller])
|
74
|
+
subject << " (#{attr[:exception].class})"
|
75
|
+
subject << " #{attr[:exception].message.inspect}"
|
76
|
+
shorten_subject(subject)
|
77
|
+
end
|
78
|
+
|
79
|
+
def formatted_controller_name(kontroller)
|
80
|
+
if kontroller.present?
|
81
|
+
"#{kontroller.controller_name}##{kontroller.action_name}"
|
82
|
+
else
|
83
|
+
''
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def shorten_subject(subject)
|
88
|
+
subject
|
89
|
+
end
|
90
|
+
|
91
|
+
def clean_backtrace(exception)
|
92
|
+
if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
|
93
|
+
Rails.backtrace_cleaner.send(:filter, exception.backtrace)
|
94
|
+
else
|
95
|
+
exception.backtrace
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def inspect_object(object)
|
100
|
+
case object
|
101
|
+
when Hash, Array
|
102
|
+
object.inspect
|
103
|
+
when ActionController::Base
|
104
|
+
"#{object.controller_name}##{object.action_name}"
|
105
|
+
else
|
106
|
+
object.to_s
|
107
|
+
end
|
108
|
+
end
|
109
|
+
helper_method :inspect_object
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: runtimeerror_notifier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.10
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Wong Liang Zan
|
9
|
+
- Chew Choon Keat
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-03-22 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: httparty
|
17
|
+
requirement: &70134270137820 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.10.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70134270137820
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &70134270135820 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.11.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70134270135820
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: shoulda
|
39
|
+
requirement: &70134270134180 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 3.3.2
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70134270134180
|
48
|
+
description: This gem installs the agent of RuntimeError.net to your application.
|
49
|
+
It handles uncaught exceptions from your application and tightly integrates exceptions
|
50
|
+
with your project management tool.
|
51
|
+
email:
|
52
|
+
- zan@liangzan.net
|
53
|
+
- choonkeat@gmail.com
|
54
|
+
executables: []
|
55
|
+
extensions: []
|
56
|
+
extra_rdoc_files: []
|
57
|
+
files:
|
58
|
+
- lib/generators/runtimeerror_notifier/install_generator.rb
|
59
|
+
- lib/generators/runtimeerror_notifier/templates/initializer.rb
|
60
|
+
- lib/runtimeerror_notifier/missing_controller.rb
|
61
|
+
- lib/runtimeerror_notifier/notifier.rb
|
62
|
+
- lib/runtimeerror_notifier.rb
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- CHANGELOG.md
|
66
|
+
homepage: https://github.com/develsadvocates/runtimeerror_notification
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 1.3.6
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.10
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Handles uncaught exceptions from your application and integrates tightly
|
90
|
+
with your project management tool.
|
91
|
+
test_files: []
|