sinatra-exceptional 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +64 -0
- data/Rakefile +11 -0
- data/lib/sinatra/exceptional.rb +71 -0
- data/lib/sinatra/exceptional/version.rb +5 -0
- data/sinatra-exceptional.gemspec +24 -0
- data/spec/sinatra_exceptional_spec.rb +69 -0
- metadata +154 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Kyle Drake
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Sinatra::Exceptional
|
2
|
+
|
3
|
+
This is a plugin for exceptional and Sinatra. I am using it manually via the Sinatra error block, and it doesn't really work automatically yet. As such, it's probably not very useful for most people.
|
4
|
+
|
5
|
+
But it's a good starting point for Sinatra support, so if you'd like to hack on this, let me know and I'll add you as a contributor!
|
6
|
+
|
7
|
+
The one feature I've added (for reason of personal requirement) is params filtering, so you can block out passwords from your exception reports.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'sinatra-exceptional', :require => 'sinatra/exceptional'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sinatra-exceptional
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
require 'sinatra'
|
26
|
+
require 'sinatra/exceptional'
|
27
|
+
|
28
|
+
configure do
|
29
|
+
Exceptional.logger
|
30
|
+
end
|
31
|
+
|
32
|
+
set :exceptional_options, {
|
33
|
+
key: 'YOUR APP KEY',
|
34
|
+
params_filter: /password/i
|
35
|
+
}
|
36
|
+
|
37
|
+
# Test with curl -d "password=sex" http://127.0.0.1:4567
|
38
|
+
post '/' do
|
39
|
+
raise StandardError, 'testing!'
|
40
|
+
end
|
41
|
+
|
42
|
+
error do
|
43
|
+
report_exception # This sends the exception to Exceptional, but does not halt.
|
44
|
+
'derp'
|
45
|
+
end
|
46
|
+
|
47
|
+
## Running the Tests
|
48
|
+
|
49
|
+
$ bundle install
|
50
|
+
$ bundle exec rake
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
59
|
+
|
60
|
+
## TODO
|
61
|
+
|
62
|
+
* Automatic exceptions
|
63
|
+
* Tests need to use webmock
|
64
|
+
* Tests for password filter (can't really do it without the mock)
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
# To run tests in the order of a seed: bundle exec rake test TESTOPTS="--seed=987"
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.pattern = "spec/**/*_spec.rb"
|
9
|
+
end
|
10
|
+
|
11
|
+
task :default => :test
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'exceptional'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'sinatra/exceptional/version'
|
4
|
+
require 'digest/md5'
|
5
|
+
|
6
|
+
module Exceptional
|
7
|
+
class Catcher
|
8
|
+
class << self
|
9
|
+
def handle_with_sinatra(exception, environment, request, opts)
|
10
|
+
if Config.should_send_to_api?
|
11
|
+
data = SinatraExceptionData.new exception, environment, request, opts
|
12
|
+
Remote.error data
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class SinatraExceptionData < ExceptionData
|
19
|
+
FILTERED_TEXT = '[FILTERED]'
|
20
|
+
|
21
|
+
def initialize(exception, environment, request, opts={})
|
22
|
+
super exception
|
23
|
+
@opts = opts
|
24
|
+
@environment = environment
|
25
|
+
@request = request
|
26
|
+
end
|
27
|
+
|
28
|
+
def framework
|
29
|
+
"sinatra"
|
30
|
+
end
|
31
|
+
|
32
|
+
def extra_stuff
|
33
|
+
params = {}
|
34
|
+
|
35
|
+
if @opts && @opts[:params_filter]
|
36
|
+
@request.params.each do |k,v|
|
37
|
+
params[k] = k.to_s.match(@opts[:params_filter]) ? FILTERED_TEXT : v
|
38
|
+
end
|
39
|
+
else
|
40
|
+
params = @request.params
|
41
|
+
end
|
42
|
+
|
43
|
+
return {} if @request.nil?
|
44
|
+
{
|
45
|
+
'request' => {
|
46
|
+
'url' => "#{@request.url}",
|
47
|
+
'parameters' => params,
|
48
|
+
'request_method' => @request.request_method.to_s,
|
49
|
+
'remote_ip' => @request.ip,
|
50
|
+
'headers' => extract_http_headers(@environment),
|
51
|
+
'session' => self.class.sanitize_session(@request)
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
module Sinatra
|
59
|
+
module Exceptional
|
60
|
+
def self.registered(app)
|
61
|
+
app.helpers do
|
62
|
+
def report_exception
|
63
|
+
::Exceptional.configure settings.exceptional_options[:key] unless ::Exceptional::Config.api_key
|
64
|
+
::Exceptional::Catcher.handle_with_sinatra env['sinatra.error'], ENV, request, settings.exceptional_options
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
register Exceptional
|
71
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/sinatra/exceptional/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Kyle Drake"]
|
6
|
+
gem.email = ["kyledrake@gmail.com"]
|
7
|
+
gem.description = %q{Sinatra adapter for use with exceptional}
|
8
|
+
gem.summary = %q{Sinatra adapter for use with exceptional, in case you need it}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "sinatra-exceptional"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Sinatra::Exceptional::VERSION
|
17
|
+
gem.add_dependency 'exceptional'
|
18
|
+
gem.add_dependency 'sinatra'
|
19
|
+
gem.add_development_dependency 'rake'
|
20
|
+
gem.add_development_dependency 'rack-test'
|
21
|
+
gem.add_development_dependency 'webmock'
|
22
|
+
gem.add_development_dependency 'json_pure'
|
23
|
+
gem.add_development_dependency 'pry'
|
24
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'production'
|
2
|
+
require File.join(File.join(File.expand_path(File.dirname(__FILE__))), '..', 'lib', 'sinatra', 'exceptional')
|
3
|
+
require 'rack/test'
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require 'webmock'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
include Rack::Test::Methods
|
9
|
+
include WebMock::API
|
10
|
+
|
11
|
+
def mock_app(&block)
|
12
|
+
@app = Sinatra.new PartyHard, &block
|
13
|
+
end
|
14
|
+
|
15
|
+
class PartyHard < Sinatra::Base
|
16
|
+
class AndrewWKPartyError < StandardError; end
|
17
|
+
|
18
|
+
set :exceptional_options, {
|
19
|
+
key: 'key'
|
20
|
+
}
|
21
|
+
register Sinatra::Exceptional
|
22
|
+
|
23
|
+
set :show_exceptions, false
|
24
|
+
set :raise_errors, true
|
25
|
+
|
26
|
+
get '/partyhard' do
|
27
|
+
'HELL YEAH'
|
28
|
+
end
|
29
|
+
|
30
|
+
get '/partyfail' do
|
31
|
+
raise AndrewWKPartyError, 'you were just kicked in the face by a crowd surfer wearing combat boots'
|
32
|
+
end
|
33
|
+
|
34
|
+
post '/login' do
|
35
|
+
raise 'hell'
|
36
|
+
end
|
37
|
+
|
38
|
+
error do
|
39
|
+
report_exception
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
def app
|
45
|
+
@app || mock_app
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'A mock app' do
|
49
|
+
it 'doesnt blow anything up' do
|
50
|
+
get '/partyhard'
|
51
|
+
last_response.ok?.must_equal true
|
52
|
+
last_response.body.must_equal 'HELL YEAH'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'throws an party error like a boss' do
|
56
|
+
lambda {
|
57
|
+
get '/partyfail'
|
58
|
+
}.must_raise PartyHard::AndrewWKPartyError
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns error with raise errors false' do
|
62
|
+
mock_app {
|
63
|
+
set :raise_errors, false
|
64
|
+
}
|
65
|
+
get '/partyfail'
|
66
|
+
last_response.status.must_equal 500
|
67
|
+
last_response.errors.must_match /AndrewWKPartyError/
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-exceptional
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Kyle Drake
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-03-21 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: exceptional
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: sinatra
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
version: "0"
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id002
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: rake
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
type: :development
|
55
|
+
version_requirements: *id003
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rack-test
|
58
|
+
prerelease: false
|
59
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
type: :development
|
67
|
+
version_requirements: *id004
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: webmock
|
70
|
+
prerelease: false
|
71
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id005
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: json_pure
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id006
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: pry
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
segments:
|
100
|
+
- 0
|
101
|
+
version: "0"
|
102
|
+
type: :development
|
103
|
+
version_requirements: *id007
|
104
|
+
description: Sinatra adapter for use with exceptional
|
105
|
+
email:
|
106
|
+
- kyledrake@gmail.com
|
107
|
+
executables: []
|
108
|
+
|
109
|
+
extensions: []
|
110
|
+
|
111
|
+
extra_rdoc_files: []
|
112
|
+
|
113
|
+
files:
|
114
|
+
- .gitignore
|
115
|
+
- Gemfile
|
116
|
+
- LICENSE
|
117
|
+
- README.md
|
118
|
+
- Rakefile
|
119
|
+
- lib/sinatra/exceptional.rb
|
120
|
+
- lib/sinatra/exceptional/version.rb
|
121
|
+
- sinatra-exceptional.gemspec
|
122
|
+
- spec/sinatra_exceptional_spec.rb
|
123
|
+
has_rdoc: true
|
124
|
+
homepage: ""
|
125
|
+
licenses: []
|
126
|
+
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
version: "0"
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
requirements: []
|
147
|
+
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 1.3.6
|
150
|
+
signing_key:
|
151
|
+
specification_version: 3
|
152
|
+
summary: Sinatra adapter for use with exceptional, in case you need it
|
153
|
+
test_files:
|
154
|
+
- spec/sinatra_exceptional_spec.rb
|