crashbreak 1.0.8 → 1.0.9
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.
- checksums.yaml +4 -4
- data/lib/crashbreak.rb +1 -0
- data/lib/crashbreak/config/configurator.rb +8 -8
- data/lib/crashbreak/exception_catcher_middleware.rb +9 -3
- data/lib/crashbreak/exception_notifier.rb +0 -5
- data/lib/crashbreak/predefined_settings.rb +36 -0
- data/lib/crashbreak/version.rb +1 -1
- data/lib/restorers/database_restorer.rb +14 -6
- data/spec/lib/exception_catcher_middleware_spec.rb +23 -3
- data/spec/lib/exception_notifier_spec.rb +0 -18
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c212f45cf4606d87ba6a1e6b51717cfce678b8d
|
4
|
+
data.tar.gz: 99f162f5a918d72b446e29fe4818e17587f01a90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 922ed25a212e112ba96d9eac46c4f57c3e95a8c61d6ed25abbf4f265d2d6fbb11f37b352f6c3b995e4af472fd277f82fc112442dc350060de5db3423233d98be
|
7
|
+
data.tar.gz: e85e395e00b7a1bab9935c7ee79f652baddfcdb9ff6c800da910567d4f49a75fee6014a6cb7c7bf7d40f6969c66e7b8632338a738a4e84e7ed5c491bdbefb83f
|
data/lib/crashbreak.rb
CHANGED
@@ -26,6 +26,7 @@ require 'crashbreak/AWS'
|
|
26
26
|
require 'crashbreak/async_exception_notifier'
|
27
27
|
require 'crashbreak/tiny_exception_notifier'
|
28
28
|
require 'crashbreak/fork_exception_notifier'
|
29
|
+
require 'crashbreak/predefined_settings'
|
29
30
|
|
30
31
|
require 'dumpers/database_dumper'
|
31
32
|
require 'dumpers/request_dumper'
|
@@ -15,35 +15,35 @@ module Crashbreak
|
|
15
15
|
attr_accessor :github_development_branch
|
16
16
|
|
17
17
|
def exception_notifier
|
18
|
-
@exception_notifier
|
18
|
+
@exception_notifier ||= ExceptionNotifier.new
|
19
19
|
end
|
20
20
|
|
21
21
|
def ignored_environments
|
22
|
-
@ignored_environments
|
22
|
+
@ignored_environments ||= ['development', 'test']
|
23
23
|
end
|
24
24
|
|
25
25
|
def error_serializers
|
26
|
-
@error_serializers
|
26
|
+
@error_serializers ||= []
|
27
27
|
end
|
28
28
|
|
29
29
|
def github_spec_file_path
|
30
|
-
@github_spec_file_path
|
30
|
+
@github_spec_file_path ||= 'spec/crashbreak_error_spec.rb'
|
31
31
|
end
|
32
32
|
|
33
33
|
def github_development_branch
|
34
|
-
@github_development_branch
|
34
|
+
@github_development_branch ||= 'master'
|
35
35
|
end
|
36
36
|
|
37
37
|
def dumpers
|
38
|
-
@dumpers
|
38
|
+
@dumpers ||= []
|
39
39
|
end
|
40
40
|
|
41
41
|
def dumper_options
|
42
|
-
@dumper_options
|
42
|
+
@dumper_options ||= {}
|
43
43
|
end
|
44
44
|
|
45
45
|
def restorer_options
|
46
|
-
@restorer_options
|
46
|
+
@restorer_options ||= {}
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -8,10 +8,12 @@ module Crashbreak
|
|
8
8
|
begin
|
9
9
|
@app.call(env)
|
10
10
|
rescue ::Exception => exception
|
11
|
-
|
12
|
-
|
11
|
+
unless skip_exception?
|
12
|
+
RequestStore.store[:exception] = exception
|
13
|
+
store_variables_from_env env
|
14
|
+
notify_about_exception
|
15
|
+
end
|
13
16
|
|
14
|
-
notify_about_exception
|
15
17
|
raise
|
16
18
|
end
|
17
19
|
end
|
@@ -57,5 +59,9 @@ module Crashbreak
|
|
57
59
|
def request(env)
|
58
60
|
Rack::Request.new(env)
|
59
61
|
end
|
62
|
+
|
63
|
+
def skip_exception?
|
64
|
+
Crashbreak.configure.ignored_environments.include?(ENV['RACK_ENV'] || ENV['RAILS_ENV'])
|
65
|
+
end
|
60
66
|
end
|
61
67
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Crashbreak
|
2
2
|
class ExceptionNotifier
|
3
3
|
def notify
|
4
|
-
return if skip_exception?
|
5
4
|
response = exceptions_repository.create serialize_exception
|
6
5
|
GithubIntegrationService.new(response).push_test if Crashbreak.configure.github_repo_name.present? && response['similar'] == false
|
7
6
|
end
|
@@ -23,10 +22,6 @@ module Crashbreak
|
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
|
-
def skip_exception?
|
27
|
-
Crashbreak.configure.ignored_environments.include? ENV['RACK_ENV']
|
28
|
-
end
|
29
|
-
|
30
25
|
def dumpers
|
31
26
|
Crashbreak.configure.dumpers
|
32
27
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Crashbreak
|
2
|
+
class PredefinedSettings
|
3
|
+
def postgresql(db_name)
|
4
|
+
restorer_for_postgresql
|
5
|
+
|
6
|
+
config.dumper_options.reverse_merge!(
|
7
|
+
dump_location: "#{Rails.root}/tmp/db.dump",
|
8
|
+
dump_command: "pg_dump -Fc #{db_name} > #{Rails.root}/tmp/db.dump"
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def heroku_postgresql(db_name, app_name)
|
13
|
+
restorer_for_postgresql
|
14
|
+
|
15
|
+
config.dumper_options.reverse_merge!(
|
16
|
+
dump_location: "#{Rails.root}/tmp/db.dump",
|
17
|
+
dump_command: "/app/vendor/heroku-toolbelt/bin/heroku pg:backups capture #{db_name} -a #{app_name} &&" +
|
18
|
+
"curl -o #{Rails.root}/tmp/db.dump `/app/vendor/heroku-toolbelt/bin/heroku pg:backups public-url --app #{app_name}`"
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def config
|
25
|
+
Crashbreak.configurator
|
26
|
+
end
|
27
|
+
|
28
|
+
def restorer_for_postgresql
|
29
|
+
config.restorer_options.reverse_merge!(
|
30
|
+
drop_test_database_command: 'dropdb crashbreak-test',
|
31
|
+
create_test_database_command: 'createdb -T template0 crashbreak-test',
|
32
|
+
restore_command: "pg_restore -O #{Rails.root}/tmp/db.dump -d crashbreak-test",
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/crashbreak/version.rb
CHANGED
@@ -7,8 +7,8 @@ module Crashbreak
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def restore
|
10
|
-
system(
|
11
|
-
system(
|
10
|
+
system(drop_test_database_command)
|
11
|
+
system(create_test_database_command)
|
12
12
|
prepare_aws
|
13
13
|
download_dump
|
14
14
|
restore_database
|
@@ -31,10 +31,6 @@ module Crashbreak
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def restore_command
|
35
|
-
Crashbreak.configure.restorer_options[:restore_command]
|
36
|
-
end
|
37
|
-
|
38
34
|
def setup_connection_to_restored_database
|
39
35
|
if Crashbreak.configure.restorer_options[:setup_database_connection].present?
|
40
36
|
Crashbreak.configure.restorer_options[:setup_database_connection].call
|
@@ -46,5 +42,17 @@ module Crashbreak
|
|
46
42
|
def database_config
|
47
43
|
@database_config ||= YAML.load(File.read('config/database.yml')).try(:[], 'test')
|
48
44
|
end
|
45
|
+
|
46
|
+
def restore_command
|
47
|
+
Crashbreak.configure.restorer_options[:restore_command]
|
48
|
+
end
|
49
|
+
|
50
|
+
def drop_test_database_command
|
51
|
+
Crashbreak.configure.restorer_options[:drop_test_database_command]
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_test_database_command
|
55
|
+
Crashbreak.configure.restorer_options[:create_test_database_command]
|
56
|
+
end
|
49
57
|
end
|
50
58
|
end
|
@@ -4,7 +4,7 @@ describe Crashbreak::ExceptionCatcherMiddleware do
|
|
4
4
|
|
5
5
|
let(:env) { Hash['action_controller.instance' => example_controller ]}
|
6
6
|
let(:example_controller) { double(:controller) }
|
7
|
-
let(:error) {
|
7
|
+
let(:error) { RegexpError.new }
|
8
8
|
|
9
9
|
before(:each) do
|
10
10
|
allow(app_with_crashes).to receive(:call).with(env).and_raise(error)
|
@@ -16,7 +16,7 @@ describe Crashbreak::ExceptionCatcherMiddleware do
|
|
16
16
|
|
17
17
|
before(:each) do
|
18
18
|
expect_any_instance_of(Crashbreak::ExceptionNotifier).to receive(:notify).and_return(true)
|
19
|
-
expect{ subject.call(env) }.to raise_error(
|
19
|
+
expect{ subject.call(env) }.to raise_error(error.class)
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'sets exception in store' do
|
@@ -32,11 +32,31 @@ describe Crashbreak::ExceptionCatcherMiddleware do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
context 'app that raises exception but current env is ignored' do
|
36
|
+
subject { described_class.new app_with_crashes }
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
expect_any_instance_of(Crashbreak::ExceptionNotifier).to_not receive(:notify)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'skips development environment by default' do
|
43
|
+
expect(ENV).to receive(:[]).with('RACK_ENV').and_return('development')
|
44
|
+
expect{ subject.call(env) }.to raise_error(error.class)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'skips all environments in config' do
|
48
|
+
Crashbreak.configure.ignored_environments = ['staging']
|
49
|
+
|
50
|
+
expect(ENV).to receive(:[]).with('RACK_ENV').and_return('staging')
|
51
|
+
expect{ subject.call(env) }.to raise_error(error.class)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
35
55
|
context 'app that works without exceptions' do
|
36
56
|
subject { described_class.new app_without_crashes }
|
37
57
|
|
38
58
|
it 'does nothing' do
|
39
|
-
expect_any_instance_of(Crashbreak::ExceptionNotifier).to_not receive(:notify)
|
59
|
+
expect_any_instance_of(Crashbreak::ExceptionNotifier).to_not receive(:notify)
|
40
60
|
expect(subject.call(env)).to eq(:ok)
|
41
61
|
end
|
42
62
|
end
|
@@ -61,24 +61,6 @@ describe Crashbreak::ExceptionNotifier do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
context 'skipping environment' do
|
65
|
-
before(:each) do
|
66
|
-
expect_any_instance_of(Crashbreak::ExceptionsRepository).to_not receive(:create)
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'skips development environment by default' do
|
70
|
-
expect(ENV).to receive(:[]).with('RACK_ENV').and_return('development')
|
71
|
-
subject.notify
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'skips all environments in config' do
|
75
|
-
Crashbreak.configure.ignored_environments = ['staging']
|
76
|
-
|
77
|
-
expect(ENV).to receive(:[]).with('RACK_ENV').and_return('staging')
|
78
|
-
subject.notify
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
64
|
context 'github integration' do
|
83
65
|
let(:error_hash) { Hash['id' => 1, 'deploy_revision' => 'test', 'similar' => false] }
|
84
66
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crashbreak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Janeczek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -240,6 +240,7 @@ files:
|
|
240
240
|
- lib/crashbreak/formatters/hash_formatter.rb
|
241
241
|
- lib/crashbreak/formatters/summary_formatter.rb
|
242
242
|
- lib/crashbreak/github_integration_service.rb
|
243
|
+
- lib/crashbreak/predefined_settings.rb
|
243
244
|
- lib/crashbreak/request_parser.rb
|
244
245
|
- lib/crashbreak/tiny_exception_notifier.rb
|
245
246
|
- lib/crashbreak/version.rb
|