crash-reporter 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/Gemfile +9 -0
- data/LICENSE +20 -0
- data/README.md +119 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/setup +7 -0
- data/crash_reporter.gemspec +27 -0
- data/lib/crash-reporter.rb +1 -0
- data/lib/crash_reporter/configure.rb +47 -0
- data/lib/crash_reporter/dsl.rb +43 -0
- data/lib/crash_reporter/reporters/github_issues.rb +41 -0
- data/lib/crash_reporter/version.rb +3 -0
- data/lib/crash_reporter.rb +26 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ee7a00bfb5d5914b68b510b747f3b97cda8b8c63
|
4
|
+
data.tar.gz: 2784937b9bb5b9deb03da1e03adb589a903b67cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7677b289b5263e59342df71b97b7224bef69b81bf8413c352e8141450c59ea3a0b97f46647171dc3aaeaa9df49ae34aea460b4de520f0384ebfc61a82f276794
|
7
|
+
data.tar.gz: af69939f76c48ad55fcde4c8111b2da9f771b2e13c902da21bca2d4dcd86382a15bb5c7b53a9c9f2a5cedce623a6a603e821771dab11750aae663d876c76cd5c
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.3
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Articulate Global, Inc
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# CrashReporter
|
2
|
+
|
3
|
+
A meta-tool to enable crash info collection from our toolset without manual effort required from users.
|
4
|
+
|
5
|
+
CrashReporter will allow you to build out crash report collection and reporting procedures in response to a failure of some kind within a given project. This is made more for cli tools. Included behaviors allow GitHub issues to be created on errors raised. Additional reporters can be built and included in the workflow as required.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'crash-reporter'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install crash-reporter
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# explicitly require desired reporters
|
27
|
+
require 'crash_reporter/reporters/github_issues'
|
28
|
+
|
29
|
+
CrashReporter.setup do |c|
|
30
|
+
c.engine = CrashReporter::GithubIssues.new('username/repo', 'auth_token')
|
31
|
+
c.tags = "crashy" # defaults to 'crash report'
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
Note that the repo name can actually be auto-discovered from the local git repo as long as you have a proper `origin` remote setup.
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class MyCoolClass
|
39
|
+
include CrashReporter::DSL
|
40
|
+
|
41
|
+
def method_that_could_crash
|
42
|
+
raise StandardError
|
43
|
+
end
|
44
|
+
|
45
|
+
# this has to be _after_ all the methods you wish to capture as we redefine the methods to include error capturing
|
46
|
+
capture_errors :method_that_could_crash
|
47
|
+
end
|
48
|
+
|
49
|
+
MyCoolClass.new.method_that_could_crash
|
50
|
+
|
51
|
+
# Will submit a GitHub issue to your repo and re-raise error!
|
52
|
+
```
|
53
|
+
|
54
|
+
Alternatively, you can handle the error submission yourself without the class-level error handling capture (possibly a more explicit method):
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
class MyCoolClass
|
58
|
+
include CrashReporter::DSL
|
59
|
+
|
60
|
+
ARealBadThing = Class.new(StandardError)
|
61
|
+
|
62
|
+
def method_that_could_crash
|
63
|
+
capture_errors do
|
64
|
+
raise ARealBadThing
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# or
|
69
|
+
|
70
|
+
def will_crash
|
71
|
+
begin
|
72
|
+
raise StandardError, "Nope!"
|
73
|
+
rescue StandardError => e
|
74
|
+
report_crash e # or any raw string message you want
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
You can additionally define your own reporters. All these reporters require is a `run` method that takes a string or an object derived from Ruby's `StandardError`. `StandardError` is the recommended method as it allows us to collect backtrace information from the crash in a uniform manner.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
class SlackReporter
|
84
|
+
def initialize(hook_url)
|
85
|
+
@hook_url = hook_url
|
86
|
+
end
|
87
|
+
|
88
|
+
def run(error)
|
89
|
+
HTTP.post(@hook_url,
|
90
|
+
json: {
|
91
|
+
text: "WE GOT PROBLEMS: #{error.message}"
|
92
|
+
})
|
93
|
+
end
|
94
|
+
end
|
95
|
+
```
|
96
|
+
|
97
|
+
Then register your new reporter:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
# Register a new webhook and use the URL here
|
101
|
+
|
102
|
+
CrashReporter.configuration.engines << SlackReporter.new('https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX')
|
103
|
+
```
|
104
|
+
|
105
|
+
Then crashes will push notifications to Slack as well! Note you can stack notifications by `<<` them to the `engines` array. You can clear these by setting `CrashReporter.configuration.engine = SlackReporter.new(...)` which will add the single reporter.
|
106
|
+
|
107
|
+
## Development
|
108
|
+
|
109
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
110
|
+
|
111
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
112
|
+
|
113
|
+
## Contributing
|
114
|
+
|
115
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/crash-reporter.
|
116
|
+
|
117
|
+
## License
|
118
|
+
|
119
|
+
This software is provided under the the [MIT license](LICENSE).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "crash-reporter"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'crash_reporter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "crash-reporter"
|
8
|
+
spec.version = CrashReporter::VERSION
|
9
|
+
spec.authors = ["Luke van der Hoeven"]
|
10
|
+
spec.email = ["hungerandthirst@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Small gem for reporting code crashes or errors to arbitrary sources}
|
13
|
+
spec.description = %q{Nope}
|
14
|
+
spec.homepage = "https://github.com/articulate/crash-reporter"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "http", "~> 0.9"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest"
|
26
|
+
spec.add_development_dependency 'webmock'
|
27
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "crash_reporter"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module CrashReporter
|
2
|
+
class Configure
|
3
|
+
attr_accessor :engines, :tags, :project_name, :repo_url, :version
|
4
|
+
|
5
|
+
def self.setup(&block)
|
6
|
+
config = new
|
7
|
+
yield config
|
8
|
+
|
9
|
+
config
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@engines = []
|
14
|
+
@tags = ['crash report']
|
15
|
+
end
|
16
|
+
|
17
|
+
# clears out all prior added engines
|
18
|
+
def engine=(engine)
|
19
|
+
@engines = [engine]
|
20
|
+
end
|
21
|
+
|
22
|
+
def tags=(*tags)
|
23
|
+
@tags = tags
|
24
|
+
end
|
25
|
+
|
26
|
+
def project_name
|
27
|
+
@project_name || repo_name
|
28
|
+
end
|
29
|
+
|
30
|
+
def repo_url
|
31
|
+
@repo_url ||= `git config --get remote.origin.url`.chomp
|
32
|
+
end
|
33
|
+
|
34
|
+
def repo_path
|
35
|
+
repo_url.split('/').last(2).join('/')
|
36
|
+
end
|
37
|
+
|
38
|
+
def repo_name
|
39
|
+
repo_url.split('/').last
|
40
|
+
end
|
41
|
+
|
42
|
+
def version=(version)
|
43
|
+
@version = version
|
44
|
+
@tags << version
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module CrashReporter
|
2
|
+
module DSL
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def capture_errors(*methods)
|
6
|
+
methods.each do |method_name|
|
7
|
+
unbound = self.instance_method(method_name)
|
8
|
+
remove_method method_name
|
9
|
+
|
10
|
+
# wrap given method in begin/rescue clause
|
11
|
+
define_method method_name do
|
12
|
+
begin
|
13
|
+
unbound.bind(self).call
|
14
|
+
rescue StandardError => e
|
15
|
+
CrashReporter.report(e)
|
16
|
+
|
17
|
+
# continue to raise original error
|
18
|
+
raise e
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.included(base)
|
26
|
+
base.extend ClassMethods
|
27
|
+
end
|
28
|
+
|
29
|
+
def capture_errors(&block)
|
30
|
+
begin
|
31
|
+
yield
|
32
|
+
rescue StandardError => e
|
33
|
+
report_crash(e)
|
34
|
+
|
35
|
+
raise e
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def report_crash(data)
|
40
|
+
CrashReporter.report(data)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'http'
|
2
|
+
|
3
|
+
module CrashReporter
|
4
|
+
class GithubIssues
|
5
|
+
GH_URI = 'https://api.github.com'
|
6
|
+
|
7
|
+
def initialize(repo_name = CrashReporter.configuration.repo_path, token)
|
8
|
+
@repo_name = repo_name
|
9
|
+
@token = token
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(data)
|
13
|
+
# Run custom formatting on Ruby StandardError objects, otherwise, just pass through
|
14
|
+
data = format(data) if data.is_a?(StandardError)
|
15
|
+
|
16
|
+
HTTP.headers(
|
17
|
+
accept: 'application/vnd.github.v3+json',
|
18
|
+
authorization: "token #{@token}"
|
19
|
+
).post("#{GH_URI}/repos/#{@repo_name}/issues", json: {
|
20
|
+
labels: CrashReporter.configuration.tags,
|
21
|
+
title: "Crash report from #{CrashReporter.configuration.project_name}",
|
22
|
+
body: data
|
23
|
+
})
|
24
|
+
|
25
|
+
data
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def format(error)
|
31
|
+
<<-ERROR
|
32
|
+
**Error:** #{error.message}
|
33
|
+
|
34
|
+
**Backtrace:**
|
35
|
+
```
|
36
|
+
#{error.backtrace.join("\n")}
|
37
|
+
```
|
38
|
+
ERROR
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'crash_reporter/version'
|
2
|
+
require 'crash_reporter/configure'
|
3
|
+
|
4
|
+
module CrashReporter
|
5
|
+
class << self
|
6
|
+
attr_writer :configuration
|
7
|
+
|
8
|
+
def configuration
|
9
|
+
@configuration ||= Configure.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def reset
|
13
|
+
@configuration = Configure.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def report(data)
|
17
|
+
configuration.engines.each do |engine|
|
18
|
+
engine.run(data)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def configure(&block)
|
23
|
+
yield configuration
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crash-reporter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luke van der Hoeven
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Nope
|
84
|
+
email:
|
85
|
+
- hungerandthirst@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".ruby-version"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- crash_reporter.gemspec
|
99
|
+
- lib/crash-reporter.rb
|
100
|
+
- lib/crash_reporter.rb
|
101
|
+
- lib/crash_reporter/configure.rb
|
102
|
+
- lib/crash_reporter/dsl.rb
|
103
|
+
- lib/crash_reporter/reporters/github_issues.rb
|
104
|
+
- lib/crash_reporter/version.rb
|
105
|
+
homepage: https://github.com/articulate/crash-reporter
|
106
|
+
licenses: []
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.4.5.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Small gem for reporting code crashes or errors to arbitrary sources
|
128
|
+
test_files: []
|