simonmenke-exception_browser_plugin_for_rails 0.0.1
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.
data/README.markdown
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "exception_browser_plugin_for_rails/version"
|
2
|
+
require 'exception_browser_plugin_for_rails/controller_extensions'
|
3
|
+
|
4
|
+
module ExceptionBrowser
|
5
|
+
@@gateway = nil
|
6
|
+
@@reporter_token = nil
|
7
|
+
@@only_in_public = true
|
8
|
+
mattr_accessor :gateway, :reporter_token, :only_in_public
|
9
|
+
end
|
10
|
+
|
11
|
+
ActionController::Base.send :include, ExceptionBrowser::Plugin
|
@@ -0,0 +1,138 @@
|
|
1
|
+
|
2
|
+
module ExceptionBrowser
|
3
|
+
module Plugin
|
4
|
+
def self.included(target)
|
5
|
+
target.send(:extend, ExceptionBrowser::Plugin::ClassMethods)
|
6
|
+
end
|
7
|
+
|
8
|
+
def rescue_action_in_public(exception)
|
9
|
+
status = response_code_for_rescue(exception)
|
10
|
+
render_optional_error_file status
|
11
|
+
log_exception(exception) if status != :not_found
|
12
|
+
end
|
13
|
+
|
14
|
+
def rescue_action_locally(exception)
|
15
|
+
add_variables_to_assigns
|
16
|
+
@template.instance_variable_set("@exception", exception)
|
17
|
+
@template.instance_variable_set("@rescues_path", File.dirname(rescues_path("stub")))
|
18
|
+
@template.send!(:assign_variables_from_controller)
|
19
|
+
|
20
|
+
@template.instance_variable_set("@contents", @template.render_file(template_path_for_local_rescue(exception), false))
|
21
|
+
|
22
|
+
response.content_type = Mime::HTML
|
23
|
+
|
24
|
+
status = response_code_for_rescue(exception)
|
25
|
+
render_for_file(rescues_path("layout"), status)
|
26
|
+
log_exception(exception) if status != :not_found and !ExceptionBrowser.only_in_public
|
27
|
+
end
|
28
|
+
|
29
|
+
module ClassMethods
|
30
|
+
|
31
|
+
def exception_data(deliverer = self, &block)
|
32
|
+
deliverer = block if block
|
33
|
+
if deliverer == self
|
34
|
+
read_inheritable_attribute(:exception_data)
|
35
|
+
else
|
36
|
+
write_inheritable_attribute(:exception_data, deliverer)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def clean_backtrace_regex
|
41
|
+
if @clean_backtrace_regex.nil?
|
42
|
+
rails_path_prefixes= Pathname.new(RAILS_ROOT).cleanpath.to_s
|
43
|
+
|
44
|
+
paths = `gem environment gempath`.strip.split(":")
|
45
|
+
gems_path_prefixes = paths.collect { |path| Pathname.new(path+"/gems").cleanpath.to_s }
|
46
|
+
|
47
|
+
paths = `ruby -e 'puts $:.reject{|p|p=="."}.join(":")'`.strip.split(":")
|
48
|
+
system_path_prefixes = paths.collect { |path| Pathname.new(path).cleanpath.to_s }
|
49
|
+
|
50
|
+
@clean_backtrace_regex = {
|
51
|
+
:rails => /^(#{Regexp.escape(rails_path_prefixes)})/,
|
52
|
+
:gems => /^(#{gems_path_prefixes.collect{|path|Regexp.escape(path)}.join('|')})/,
|
53
|
+
:system => /^(#{system_path_prefixes.collect{|path|Regexp.escape(path)}.join('|')})/
|
54
|
+
}
|
55
|
+
end
|
56
|
+
@clean_backtrace_regex
|
57
|
+
end
|
58
|
+
|
59
|
+
def sanitaize_backtrace_entry(line)
|
60
|
+
line = line.strip
|
61
|
+
line.gsub!('in `', "")
|
62
|
+
line.gsub!("'", "")
|
63
|
+
line.gsub!(clean_backtrace_regex[:rails], "[RAILS_ROOT]")
|
64
|
+
line.gsub!(clean_backtrace_regex[:gems], "[GEM]")
|
65
|
+
line.gsub!(clean_backtrace_regex[:system], "[SYSTEM]")
|
66
|
+
Pathname.new(line).cleanpath.to_s
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
def exception_data(exception)
|
72
|
+
deliverer = self.class.exception_data
|
73
|
+
data = case deliverer
|
74
|
+
when nil then {}
|
75
|
+
when Symbol then send(deliverer)
|
76
|
+
when Proc then deliverer.call(self)
|
77
|
+
end
|
78
|
+
|
79
|
+
{ :exception => {
|
80
|
+
:class_name => exception.class.name,
|
81
|
+
:controller_name => controller_name,
|
82
|
+
:action_name => action_name,
|
83
|
+
:message => exception.message,
|
84
|
+
:extra_message => data,
|
85
|
+
:guid => Digest::SHA1.hexdigest(Time.new.to_f.to_s + "." + (rand(8999)+1000).to_s).upcase,
|
86
|
+
:raised_at => Time.new,
|
87
|
+
:environment => environment_data(exception),
|
88
|
+
:request => {
|
89
|
+
:protocol => request.protocol,
|
90
|
+
:host => request.env["HTTP_HOST"],
|
91
|
+
:uri => request.request_uri,
|
92
|
+
:method => request.method.to_s,
|
93
|
+
:format => request.format.to_s,
|
94
|
+
:parameters => request.parameters.to_hash,
|
95
|
+
:rails_root => Pathname.new(RAILS_ROOT).cleanpath.to_s
|
96
|
+
},
|
97
|
+
:backtrace => backtrace_data(exception.backtrace)
|
98
|
+
} }.to_xml.sub(/^<hash>/, "").sub(/<\/hash>$/, "")
|
99
|
+
end
|
100
|
+
|
101
|
+
def backtrace_data(raw_lines)
|
102
|
+
raw_lines = raw_lines.collect { |string| string.split("\n") }.flatten.collect(&:strip)
|
103
|
+
raw_lines = raw_lines.reject { |string| string.blank? or (string =~ /^(On line|\d+\:)/) }
|
104
|
+
return raw_lines.collect { |raw_line| backtrace_entry_data(raw_line) }
|
105
|
+
end
|
106
|
+
|
107
|
+
def backtrace_entry_data(raw_line)
|
108
|
+
raw_line = self.class.sanitaize_backtrace_entry(raw_line).split(':')
|
109
|
+
data = { :file => raw_line.shift,
|
110
|
+
:line => raw_line.shift.to_i }
|
111
|
+
data[:method] = raw_line.shift unless raw_line.empty?
|
112
|
+
data
|
113
|
+
end
|
114
|
+
|
115
|
+
def environment_data(exception)
|
116
|
+
data = {
|
117
|
+
"PROCESS" => $$,
|
118
|
+
"SERVER" => `hostname -s`.chomp }
|
119
|
+
self.request.env.each { |k,v| data[k] = v }
|
120
|
+
data
|
121
|
+
end
|
122
|
+
|
123
|
+
def log_exception(exception)
|
124
|
+
return if ExceptionBrowser.gateway.blank? or ExceptionBrowser.reporter_token.blank?
|
125
|
+
|
126
|
+
url = URI.parse(ExceptionBrowser.gateway)
|
127
|
+
|
128
|
+
req = Net::HTTP::Post.new(url.path)
|
129
|
+
req.set_content_type "text/xml"
|
130
|
+
req.basic_auth ExceptionBrowser.reporter_token, 'x'
|
131
|
+
req.body = exception_data(exception)
|
132
|
+
|
133
|
+
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
|
134
|
+
res.error! unless res.is_a? Net::HTTPSuccess
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simonmenke-exception_browser_plugin_for_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Simon Menke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-12 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Allows Rails to forward exceptions to exception_browser
|
17
|
+
email:
|
18
|
+
- simon@5xm.org
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- History.txt
|
25
|
+
- License.txt
|
26
|
+
files:
|
27
|
+
- History.txt
|
28
|
+
- License.txt
|
29
|
+
- README.markdown
|
30
|
+
- Rakefile
|
31
|
+
- lib/exception_browser_plugin_for_rails.rb
|
32
|
+
- lib/exception_browser_plugin_for_rails/controller_extensions.rb
|
33
|
+
- lib/exception_browser_plugin_for_rails/version.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/simonmenke/exception_browser_plugin_for_rails
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options:
|
38
|
+
- --main
|
39
|
+
- README.markdown
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: "0"
|
47
|
+
version:
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
requirements: []
|
55
|
+
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.0.1
|
58
|
+
signing_key:
|
59
|
+
specification_version: 2
|
60
|
+
summary: Allows Rails to forward exceptions to exception_browser
|
61
|
+
test_files: []
|
62
|
+
|