ixtlan-error-handler 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,6 +25,9 @@ module Ixtlan
25
25
  module Errors
26
26
  class Cuba < ::CubaAPI
27
27
  define do
28
+ on get, 'last' do
29
+ write Ixtlan::Errors::Error.last
30
+ end
28
31
  on get, :number do |number|
29
32
  write Ixtlan::Errors::Error.get!( number )
30
33
  end
@@ -34,4 +37,4 @@ module Ixtlan
34
37
  end
35
38
  end
36
39
  end
37
- end
40
+ end
@@ -68,7 +68,7 @@ module Ixtlan
68
68
  session,
69
69
  params )
70
70
 
71
- if not @to_emails.blank? and not @from_email.blank?
71
+ if not error.id.nil? and not @to_emails.blank? and not @from_email.blank?
72
72
  Mailer.error_notification( @from_email,
73
73
  @to_emails,
74
74
  exception,
@@ -88,9 +88,7 @@ module Ixtlan
88
88
  def dump_environment( exception, request, response, session , params )
89
89
  dump = model.new
90
90
 
91
- dump.request = dump_hashmap( request )
92
-
93
- dump.response = dump_hashmap( response )
91
+ dump.request = dump_hashmap( request, '', true )
94
92
 
95
93
  dump.session = dump_hashmap( session )
96
94
 
@@ -101,13 +99,15 @@ module Ixtlan
101
99
  dump.clazz = exception.class.to_s
102
100
 
103
101
  dump.backtrace = exception.backtrace.join("\n") if exception.backtrace
104
-
105
- dump if dump.save
102
+
103
+ dump.save
104
+ dump
106
105
  end
107
106
 
108
- def dump_hashmap(map, indent = '')
107
+ def dump_hashmap(map, indent = '', capital_keys_only = false )
109
108
  result = ''
110
109
  map.each do |key,value|
110
+ if !capital_keys_only || (key =~ /^[A-Z_]+$/) != nil
111
111
  if value.is_a? Hash
112
112
  result << "#{indent}#{key} => {\n"
113
113
  result << dump_hashmap(value, "#{indent} ")
@@ -115,7 +115,9 @@ module Ixtlan
115
115
  else
116
116
  result << "#{indent}#{key} => #{value.nil? ? 'nil': value}\n"
117
117
  end
118
+ end
118
119
  end
120
+ result.strip!
119
121
  result
120
122
  end
121
123
 
@@ -18,6 +18,7 @@
18
18
  # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
+ require 'rack/request'
21
22
  module Ixtlan
22
23
  module Errors
23
24
  class Rack
@@ -61,8 +62,9 @@ module Ixtlan
61
62
  @app.call(env)
62
63
  rescue Exception => e
63
64
  status = @map[ e.class ] || 500
64
- if status >= 500
65
- @dumper.dump( e, env, {}, {}, {} )
65
+ if status >= 500
66
+ req = ::Rack::Request.new env
67
+ @dumper.dump( e, env, {}, req.session, req.params )
66
68
  end
67
69
  if @dump_to_console
68
70
  warn "[Ixtlan] #{e.class}: #{e.message}"
@@ -76,4 +78,4 @@ module Ixtlan
76
78
 
77
79
  end
78
80
  end
79
- end
81
+ end
@@ -25,21 +25,29 @@ module Ixtlan
25
25
 
26
26
  include DataMapper::Resource
27
27
 
28
+ def self.storage_name(arg)
29
+ 'ixtlan_errors'
30
+ end
31
+
28
32
  property :id, Serial
29
33
 
30
34
  property :clazz, String, :required => true, :length => 64
31
35
  property :message, String, :required => true, :length => 255
32
- property :backtrace, Text, :required => true, :length => 32768
33
- property :request, Text, :required => true, :length => 64536
34
- property :response, Text, :required => true, :length => 32768
35
- property :session, Text, :required => true, :length => 16384
36
- property :parameters, Text, :required => true, :length => 32768
36
+ property :backtrace, Text, :required => false, :length => 32768
37
+ property :request, Text, :required => false, :length => 32768
38
+ property :session, Text, :required => false, :length => 16384
39
+ property :parameters, Text, :required => false, :length => 32768
40
+ #property :body, Text, :required => false, :length => 64536
37
41
 
38
42
  property :created_at, DateTime
39
43
 
40
44
  before :save do
41
45
  self.created_at = DateTime.now
42
46
  end
47
+
48
+ def to_s
49
+ "#{clazz}: #{message}"
50
+ end
43
51
  end
44
52
  end
45
- end
53
+ end
@@ -1,26 +1,9 @@
1
1
  require 'dm-core'
2
2
  require 'dm-migrations'
3
3
  require 'slf4r/ruby_logger'
4
+ require 'ixtlan/errors/resource'
4
5
 
5
- class Error
6
- include DataMapper::Resource
7
-
8
- property :id, Serial
9
-
10
- property :message, String
11
- property :clazz, String
12
- property :request, Text
13
- property :response, Text
14
- property :session, Text
15
- property :parameters, Text
16
- property :backtrace, Text
17
-
18
- property :created_at, DateTime
19
-
20
- before :save do
21
- self.created_at = DateTime.now
22
- end
23
- end
6
+ Error = Ixtlan::Errors::Error
24
7
 
25
8
  require 'pony'
26
9
  Pony.options = { :via => :test }
@@ -55,36 +38,6 @@ class Controller < Hash
55
38
  end
56
39
  end
57
40
 
58
- class NilClass
59
- def blank?
60
- true
61
- end
62
- end
63
-
64
- class String
65
- def blank?
66
- size == 0
67
- end
68
- end
69
-
70
- class Fixnum
71
- def days
72
- self
73
- end
74
- def ago
75
- DateTime.now - 86000 * self
76
- end
77
- end
78
-
79
- class DateTime
80
- def tv_sec
81
- sec
82
- end
83
- def tv_usec
84
- 0
85
- end
86
- end
87
-
88
41
  DataMapper.setup(:default, "sqlite3::memory:")
89
42
  DataMapper.finalize
90
43
  DataMapper.auto_migrate!
@@ -113,7 +66,7 @@ describe Ixtlan::Errors::Dumper do
113
66
  end
114
67
 
115
68
  it "should clean up error dumps" do
116
- Error.create(:message => 'msg')
69
+ Error.create(:message => 'msg', :clazz => StandardError.to_s)
117
70
  Error.all.size.should > 0
118
71
  @dumper.keep_dumps = 0
119
72
  Error.all.size.should == 0
metadata CHANGED
@@ -1,158 +1,151 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ixtlan-error-handler
3
- version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.4.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Christian Meier
14
- autorequire:
9
+ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-12-29 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-01-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: slf4r
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 11
29
- segments:
30
- - 0
31
- - 4
32
- - 2
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.4.2
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
33
26
  version: 0.4.2
27
+ none: false
28
+ prerelease: false
34
29
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
30
+ - !ruby/object:Gem::Dependency
37
31
  name: rspec
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.11'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.11'
43
+ none: false
38
44
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 21
45
- segments:
46
- - 2
47
- - 11
48
- version: "2.11"
49
45
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
46
+ - !ruby/object:Gem::Dependency
52
47
  name: rake
53
- prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 75
60
- segments:
61
- - 10
62
- - 0
63
- - 2
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: 10.0.2
53
+ none: false
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - "~>"
57
+ - !ruby/object:Gem::Version
64
58
  version: 10.0.2
59
+ none: false
60
+ prerelease: false
65
61
  type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
62
+ - !ruby/object:Gem::Dependency
68
63
  name: dm-core
69
- prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- hash: 31
76
- segments:
77
- - 1
78
- - 2
79
- - 0
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.2.0
69
+ none: false
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
80
74
  version: 1.2.0
75
+ none: false
76
+ prerelease: false
81
77
  type: :development
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
78
+ - !ruby/object:Gem::Dependency
84
79
  name: dm-migrations
85
- prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
89
- - - ~>
90
- - !ruby/object:Gem::Version
91
- hash: 31
92
- segments:
93
- - 1
94
- - 2
95
- - 0
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: 1.2.0
85
+ none: false
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
96
90
  version: 1.2.0
91
+ none: false
92
+ prerelease: false
97
93
  type: :development
98
- version_requirements: *id005
99
- - !ruby/object:Gem::Dependency
94
+ - !ruby/object:Gem::Dependency
100
95
  name: dm-sqlite-adapter
101
- prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
103
- none: false
104
- requirements:
105
- - - ~>
106
- - !ruby/object:Gem::Version
107
- hash: 31
108
- segments:
109
- - 1
110
- - 2
111
- - 0
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: 1.2.0
101
+ none: false
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - "~>"
105
+ - !ruby/object:Gem::Version
112
106
  version: 1.2.0
107
+ none: false
108
+ prerelease: false
113
109
  type: :development
114
- version_requirements: *id006
115
- - !ruby/object:Gem::Dependency
110
+ - !ruby/object:Gem::Dependency
116
111
  name: pony
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.4'
117
+ none: false
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '1.4'
123
+ none: false
117
124
  prerelease: false
118
- requirement: &id007 !ruby/object:Gem::Requirement
119
- none: false
120
- requirements:
121
- - - ~>
122
- - !ruby/object:Gem::Version
123
- hash: 7
124
- segments:
125
- - 1
126
- - 4
127
- version: "1.4"
128
125
  type: :development
129
- version_requirements: *id007
130
- - !ruby/object:Gem::Dependency
126
+ - !ruby/object:Gem::Dependency
131
127
  name: copyright-header
132
- prerelease: false
133
- requirement: &id008 !ruby/object:Gem::Requirement
134
- none: false
135
- requirements:
136
- - - ~>
137
- - !ruby/object:Gem::Version
138
- hash: 25
139
- segments:
140
- - 1
141
- - 0
142
- - 7
128
+ version_requirements: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: 1.0.7
133
+ none: false
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
143
138
  version: 1.0.7
139
+ none: false
140
+ prerelease: false
144
141
  type: :development
145
- version_requirements: *id008
146
142
  description: dump errors on filesystem and notify developers, map different errors to specific pages
147
- email:
143
+ email:
148
144
  - m.kristian@web.de
149
145
  executables: []
150
-
151
146
  extensions: []
152
-
153
147
  extra_rdoc_files: []
154
-
155
- files:
148
+ files:
156
149
  - MIT-LICENSE
157
150
  - README.textile
158
151
  - lib/ixtlan-error-handler.rb
@@ -161,7 +154,6 @@ files:
161
154
  - lib/ixtlan/errors/cuba.rb
162
155
  - lib/ixtlan/errors/dumper.rb
163
156
  - lib/ixtlan/errors/error_handling.rb~
164
- - lib/ixtlan/errors/mailer/error_notification.erb
165
157
  - lib/ixtlan/errors/error.rb~
166
158
  - lib/ixtlan/errors/resource.rb~
167
159
  - lib/ixtlan/errors/rescue_module.rb~
@@ -178,44 +170,40 @@ files:
178
170
  - lib/ixtlan/errors/rack.rb~
179
171
  - lib/ixtlan/errors/rack.rb
180
172
  - lib/ixtlan/errors/serializer.rb
173
+ - lib/ixtlan/errors/mailer/error_notification.erb
181
174
  - spec/error_handler_spec.rb
182
175
  - spec/dumper_spec.rb
183
176
  - spec/error_dumper_spec.rb~
184
177
  - spec/error_handler_spec.rb~
185
178
  homepage: http://github.com/mkristian/ixtlan-error-handler
186
- licenses:
179
+ licenses:
187
180
  - MIT
188
- post_install_message:
189
- rdoc_options:
190
- - --main
181
+ post_install_message:
182
+ rdoc_options:
183
+ - "--main"
191
184
  - README.textile
192
- require_paths:
185
+ require_paths:
193
186
  - lib
194
- required_ruby_version: !ruby/object:Gem::Requirement
195
- none: false
196
- requirements:
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
197
189
  - - ">="
198
- - !ruby/object:Gem::Version
199
- hash: 3
200
- segments:
201
- - 0
202
- version: "0"
203
- required_rubygems_version: !ruby/object:Gem::Requirement
190
+ - !ruby/object:Gem::Version
191
+ version: !binary |-
192
+ MA==
204
193
  none: false
205
- requirements:
194
+ required_rubygems_version: !ruby/object:Gem::Requirement
195
+ requirements:
206
196
  - - ">="
207
- - !ruby/object:Gem::Version
208
- hash: 3
209
- segments:
210
- - 0
211
- version: "0"
197
+ - !ruby/object:Gem::Version
198
+ version: !binary |-
199
+ MA==
200
+ none: false
212
201
  requirements: []
213
-
214
- rubyforge_project:
215
- rubygems_version: 1.8.15
216
- signing_key:
202
+ rubyforge_project:
203
+ rubygems_version: 1.8.24
204
+ signing_key:
217
205
  specification_version: 3
218
206
  summary: dump errors on filesystem and notify developers
219
- test_files:
207
+ test_files:
220
208
  - spec/error_handler_spec.rb
221
209
  - spec/dumper_spec.rb