whoopsie 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +144 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/whoopsie.js +2 -0
- data/app/assets/javascripts/whoopsie/tracekit-config.js +49 -0
- data/app/assets/javascripts/whoopsie/tracekit.js +1166 -0
- data/app/controllers/whoopsie/application_controller.rb +4 -0
- data/app/controllers/whoopsie/errors_controller.rb +50 -0
- data/app/helpers/whoopsie/whoopsie_helper.rb +18 -0
- data/config/routes.rb +5 -0
- data/lib/whoopsie.rb +20 -0
- data/lib/whoopsie/engine.rb +9 -0
- data/lib/whoopsie/railtie.rb +39 -0
- data/lib/whoopsie/version.rb +3 -0
- data/spec/controllers/whoopsie/errors_controller_spec.rb +71 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +3 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/welcome_controller.rb +4 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +17 -0
- data/spec/dummy/app/views/welcome/show.html.erb +3 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +38 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +38 -0
- data/spec/dummy/config/environments/production.rb +76 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/examples.txt +11 -0
- data/spec/lib/whoopsie_spec.rb +41 -0
- data/spec/rails_helper.rb +57 -0
- data/spec/spec_helper.rb +92 -0
- metadata +262 -0
@@ -0,0 +1,50 @@
|
|
1
|
+
require_dependency 'whoopsie/application_controller'
|
2
|
+
|
3
|
+
module Whoopsie
|
4
|
+
class ErrorsController < ApplicationController
|
5
|
+
skip_before_action :verify_authenticity_token
|
6
|
+
|
7
|
+
class JavaScriptError < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
newrelic_ignore if defined?(NewRelic) && respond_to?(:newrelic_ignore)
|
11
|
+
|
12
|
+
# Create a JavaScript exception and notify as configured
|
13
|
+
# Params:
|
14
|
+
# error_report: A hash containing :message as a string
|
15
|
+
# extra: Contextual data
|
16
|
+
def create
|
17
|
+
if Rails.application.config.whoopsie.enable
|
18
|
+
exception = JavaScriptError.new(report_params[:message])
|
19
|
+
report_params.merge!(extra: params[:extra]) if params[:extra]
|
20
|
+
ExceptionNotifier.notify_exception(
|
21
|
+
exception,
|
22
|
+
env: request.env,
|
23
|
+
data: report_params
|
24
|
+
)
|
25
|
+
render plain: 'error acknowledged', status: :ok
|
26
|
+
else
|
27
|
+
render plain: 'error ignored', status: :accepted
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Call this method to test Whoopsie in your live production app.
|
32
|
+
def bang
|
33
|
+
fail('boom!')
|
34
|
+
end
|
35
|
+
|
36
|
+
# Make sure Whoopsie is available
|
37
|
+
def ping
|
38
|
+
app_name = Rails.application.engine_name
|
39
|
+
db_status = !ActiveRecord::Base.connection.tables.empty? ? :ok : :empty
|
40
|
+
render plain: "#{app_name} #{db_status}"
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# The :extra parameter may or may not be included as part of the :error_report
|
46
|
+
def report_params
|
47
|
+
params.require(:error_report).permit(:message, :extra)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Whoopsie
|
2
|
+
module WhoopsieHelper
|
3
|
+
def whoopsie_config(extra = {})
|
4
|
+
(<<-EOS).strip_heredoc.html_safe
|
5
|
+
<script>
|
6
|
+
window.Whoopsie = window.Whoopsie || {};
|
7
|
+
window.Whoopsie.enabled = #{Rails.application.config.whoopsie.enable.to_json};
|
8
|
+
window.Whoopsie.client_notification_url = "#{errors_path}";
|
9
|
+
window.Whoopsie.extra = function(){
|
10
|
+
var extra = #{extra.to_json};
|
11
|
+
extra.location = window.location.toString();
|
12
|
+
return extra;
|
13
|
+
}
|
14
|
+
</script>
|
15
|
+
EOS
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/config/routes.rb
ADDED
data/lib/whoopsie.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
require 'exception_notification'
|
4
|
+
require 'whoopsie/engine'
|
5
|
+
require 'whoopsie/railtie'
|
6
|
+
|
7
|
+
module Whoopsie
|
8
|
+
class << self
|
9
|
+
def report_and_swallow
|
10
|
+
yield
|
11
|
+
rescue StandardError => e
|
12
|
+
handle_exception(e)
|
13
|
+
end
|
14
|
+
|
15
|
+
def handle_exception(exception, data = {})
|
16
|
+
return ExceptionNotifier.notify_exception(exception, data) if Rails.application.config.whoopsie.enable
|
17
|
+
fail(exception)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Whoopsie
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
Config = Struct.new(:enable, :recipients, :sender, :email_prefix)
|
4
|
+
config.whoopsie = Config.new
|
5
|
+
|
6
|
+
initializer 'whoopsie.configure_middleware' do
|
7
|
+
Rails.application.middleware.insert_before(
|
8
|
+
ActiveRecord::ConnectionAdapters::ConnectionManagement,
|
9
|
+
ExceptionNotification::Rack
|
10
|
+
)
|
11
|
+
|
12
|
+
# Include the helper
|
13
|
+
ActionView::Base.send(:include, WhoopsieHelper)
|
14
|
+
|
15
|
+
ExceptionNotification.configure do |config|
|
16
|
+
# Ignore additional exception types.
|
17
|
+
|
18
|
+
# ActiveRecord::RecordNotFound, AbstractController::ActionNotFound and
|
19
|
+
# ActionController::RoutingError are already added.
|
20
|
+
# config.ignored_exceptions += %w{ActionView::TemplateError CustomError}
|
21
|
+
|
22
|
+
# Adds a condition to decide when an exception must be ignored or not.
|
23
|
+
# The ignore_if method can be invoked multiple times to add extra conditions.
|
24
|
+
# config.ignore_if do |exception, options|
|
25
|
+
# ! Rails.application.config.whoopsie.enable
|
26
|
+
# end
|
27
|
+
|
28
|
+
if Rails.application.config.whoopsie.enable
|
29
|
+
config.add_notifier(
|
30
|
+
:email,
|
31
|
+
email_prefix: Rails.application.config.whoopsie.email_prefix || '[ERROR] ',
|
32
|
+
sender_address: Rails.application.config.whoopsie.sender,
|
33
|
+
exception_recipients: Rails.application.config.whoopsie.recipients
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
module Whoopsie
|
4
|
+
RSpec.describe ErrorsController, type: :controller do
|
5
|
+
routes { Whoopsie::Engine.routes }
|
6
|
+
|
7
|
+
context '.ping' do
|
8
|
+
it 'returns a 200 status' do
|
9
|
+
get :ping
|
10
|
+
expect(response).to be_success
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# This method allows you to test Whoopsie from within your live application.
|
15
|
+
context '.bang' do
|
16
|
+
it 'raises an error' do
|
17
|
+
expect do
|
18
|
+
get :bang
|
19
|
+
end.to raise_error(RuntimeError)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context '.create' do
|
24
|
+
let(:valid_params) do
|
25
|
+
{
|
26
|
+
error_report: {
|
27
|
+
message: 'I made a terrible mistake!',
|
28
|
+
},
|
29
|
+
extra: 'And it is what it is.'
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when Whoopsie is enabled' do
|
34
|
+
before do
|
35
|
+
Rails.application.config.whoopsie.enable = true
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with valid params' do
|
39
|
+
it 'returns a 200 status' do
|
40
|
+
post :create, valid_params
|
41
|
+
expect(response).to be_ok
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'calls .notify_exception' do
|
45
|
+
expect(ExceptionNotifier).to receive(:notify_exception)
|
46
|
+
post :create, valid_params
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with missing params' do
|
51
|
+
it 'raises an exception' do
|
52
|
+
expect do
|
53
|
+
post :create
|
54
|
+
end.to raise_error(ActionController::ParameterMissing)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when Whoopsie is disabled' do
|
60
|
+
before do
|
61
|
+
Rails.application.config.whoopsie.enable = false
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns a 202 status' do
|
65
|
+
post :create, valid_params
|
66
|
+
expect(response).to be_accepted
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/spec/dummy/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
|
6
|
+
<%= whoopsie_config({user_id: 123}) %>
|
7
|
+
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
|
8
|
+
<%= csrf_meta_tags %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
<script>
|
14
|
+
window.loggingInformation = {time: (new Date()).toString(), location: window.location.toString()};
|
15
|
+
</script>
|
16
|
+
</body>
|
17
|
+
</html>
|
data/spec/dummy/bin/rake
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
|
6
|
+
|
7
|
+
Dir.chdir APP_ROOT do
|
8
|
+
# This script is a starting point to setup your application.
|
9
|
+
# Add necessary setup steps to this file:
|
10
|
+
|
11
|
+
puts "== Installing dependencies =="
|
12
|
+
system "gem install bundler --conservative"
|
13
|
+
system "bundle check || bundle install"
|
14
|
+
|
15
|
+
# puts "\n== Copying sample files =="
|
16
|
+
# unless File.exist?("config/database.yml")
|
17
|
+
# system "cp config/database.yml.sample config/database.yml"
|
18
|
+
# end
|
19
|
+
|
20
|
+
puts "\n== Preparing database =="
|
21
|
+
system "bin/rake db:setup"
|
22
|
+
|
23
|
+
puts "\n== Removing old logs and tempfiles =="
|
24
|
+
system "rm -f log/*"
|
25
|
+
system "rm -rf tmp/cache"
|
26
|
+
|
27
|
+
puts "\n== Restarting application server =="
|
28
|
+
system "touch tmp/restart.txt"
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
# Pick the frameworks you want:
|
4
|
+
require "active_record/railtie"
|
5
|
+
require "action_controller/railtie"
|
6
|
+
require "action_mailer/railtie"
|
7
|
+
require "action_view/railtie"
|
8
|
+
require "sprockets/railtie"
|
9
|
+
require "rails/test_unit/railtie"
|
10
|
+
|
11
|
+
Bundler.require(*Rails.groups)
|
12
|
+
require "whoopsie"
|
13
|
+
|
14
|
+
module Dummy
|
15
|
+
class Application < Rails::Application
|
16
|
+
# Settings in config/environments/* take precedence over those specified here.
|
17
|
+
# Application configuration should go into files in config/initializers
|
18
|
+
# -- all .rb files in that directory are automatically loaded.
|
19
|
+
|
20
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
21
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
22
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
23
|
+
|
24
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
25
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
26
|
+
# config.i18n.default_locale = :de
|
27
|
+
|
28
|
+
config.action_mailer.delivery_method = :letter_opener
|
29
|
+
config.action_mailer.perform_deliveries = true
|
30
|
+
config.action_mailer.raise_delivery_errors = true
|
31
|
+
|
32
|
+
config.whoopsie.enable = true
|
33
|
+
config.whoopsie.email_prefix = '[ERROR TEST] '
|
34
|
+
config.whoopsie.recipients = ["whoopsie@example.com"]
|
35
|
+
config.whoopsie.sender = "whoopsie@example.com"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
development:
|
4
|
+
adapter: sqlite3
|
5
|
+
database: db/development.sqlite3
|
6
|
+
pool: 5
|
7
|
+
timeout: 5000
|
8
|
+
|
9
|
+
# Warning: The database defined as "test" will be erased and
|
10
|
+
# re-generated from your development database when you run "rake".
|
11
|
+
# Do not set this db to the same as development or production.
|
12
|
+
test:
|
13
|
+
adapter: sqlite3
|
14
|
+
database: db/test.sqlite3
|
15
|
+
pool: 5
|
16
|
+
timeout: 5000
|
17
|
+
|
18
|
+
production:
|
19
|
+
adapter: sqlite3
|
20
|
+
database: db/production.sqlite3
|
21
|
+
pool: 5
|
22
|
+
timeout: 5000
|