rack-unreloader 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 63e0754f2064aacba7745d52c60d136019dd5fdf
4
- data.tar.gz: 31d3d8223106f59d5fa739b429cbf08d6d47db31
2
+ SHA256:
3
+ metadata.gz: 513c06d3763473095bfcfb9b22a55d5bff7e5ede857a957934923062dd72473f
4
+ data.tar.gz: 03bc800248c21507ac209104593019e3fc69a398f32a02b7e4e3371d4824d162
5
5
  SHA512:
6
- metadata.gz: 6645aa444fd1c88c52c09f0de56894f640cf9404624f0e25197071b1498d1aa7745a1bb9a8e9416f3cc7d8aeacf4f993e552adaa06f4b1386be95db43aef4272
7
- data.tar.gz: 26811ff5218e1fe20e15f0619dcfb4d4dbabcba2819c82e8c46f428fdfb1714a3348a12a931ba8065d5f6cb182336e989e6d98d93e7a2ac633f4c6c7d783fc43
6
+ metadata.gz: 83c6ad5ee6aa7650bf5de240949a20c54b4560c1ef943f3ebc8599a22788cd88c96214ee0f26d540f17eb16f26fe282357f52c1cd4b415980250bc18281675d7
7
+ data.tar.gz: 96a012e44fc868f4a3a2aa1395c5710156ef9302f36e23a3718af364e03e4f5bd411959c8fa2cf590eede2201208117ab4a47a36def1c6e95a5bb87c0c045978
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ = 1.7.0 (2019-03-18)
2
+
3
+ * Add :handle_reload_errors option, for returning backtrace with error if there is an exception when reloading (jeremyevans)
4
+
1
5
  = 1.6.0 (2017-02-24)
2
6
 
3
7
  * Add Unreloader#strip_path_prefix, designed to support chrooting (jeremyevans)
@@ -62,6 +62,11 @@ When the +:subclasses+ option is given, only subclasses of the given classes
62
62
  will be unloaded before reloading the file. It is recommended that
63
63
  you use a +:subclasses+ option when using <tt>Rack::Unreloader</tt>.
64
64
 
65
+ When the +:handle_reload_errors+ option is given, most exceptions raised during
66
+ reloading will cause the backtrace to be returned, instead of raising the error
67
+ externally. This can be useful if no middleware that wrap the Unreloader are
68
+ rescuing exceptions.
69
+
65
70
  == Dependency Handling
66
71
 
67
72
  If your +app.rb+ requires a +models.rb+ file that you also want to get reloaded:
@@ -58,12 +58,13 @@ module Rack
58
58
  @app_block = block
59
59
  if opts.fetch(:reload, true)
60
60
  @cooldown = opts.fetch(:cooldown, 1)
61
+ @handle_reload_errors = opts[:handle_reload_errors]
61
62
  @last = Time.at(0)
62
63
  Kernel.require 'rack/unreloader/reloader'
63
64
  @reloader = Reloader.new(opts)
64
65
  reload!
65
66
  else
66
- @reloader = @cooldown = false
67
+ @reloader = @cooldown = @handle_reload_errors = false
67
68
  end
68
69
  end
69
70
 
@@ -71,7 +72,13 @@ module Rack
71
72
  # Call the app with the environment.
72
73
  def call(env)
73
74
  if @cooldown && Time.now > @last + @cooldown
74
- MUTEX.synchronize{reload!}
75
+ begin
76
+ MUTEX.synchronize{reload!}
77
+ rescue StandardError, ScriptError => e
78
+ raise unless @handle_reload_errors
79
+ content = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}"
80
+ return [500, {'Content-Type' => 'text/plain', 'Content-Length' => content.bytesize.to_s}, [content]]
81
+ end
75
82
  @last = Time.now
76
83
  end
77
84
  @app_block.call.call(env)
@@ -1,6 +1,7 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), '../lib/rack/unreloader')
2
2
  require 'rubygems'
3
3
  $: << 'lib'
4
+ ENV['MT_NO_PLUGINS'] = '1' # Work around stupid autoloading of plugins
4
5
  gem 'minitest'
5
6
  require 'minitest/autorun'
6
7
  require 'minitest/hooks'
@@ -157,6 +157,28 @@ describe Rack::Unreloader do
157
157
  %r{\ANew classes in .*spec/app\.rb: App\z}
158
158
  end
159
159
 
160
+ it "should support :handle_reload_errors option to return backtrace if there is an error reloading" do
161
+ ru(:handle_reload_errors=>true).call({}).must_equal [1]
162
+ update_app("module App; def self.call(env) @a end; @a ||= []; raise 'foo'; end")
163
+ rack_response = ru.call({})
164
+ rack_response[0].must_equal 500
165
+ rack_response[1]['Content-Type'].must_equal 'text/plain'
166
+ rack_response[1]['Content-Length'].must_match(rack_response[2][0].bytesize.to_s)
167
+ rack_response[2][0].must_match(/\/spec\/app\.rb:1/)
168
+ defined?(::App).must_be_nil
169
+ update_app(code(2))
170
+ ru.call({}).must_equal [2]
171
+ log_match %r{\ALoading.*spec/app\.rb\z},
172
+ %r{\ANew classes in .*spec/app\.rb: App\z},
173
+ %r{\AUnloading.*spec/app\.rb\z},
174
+ "Removed constant App",
175
+ %r{\ALoading.*spec/app\.rb\z},
176
+ %r{\AFailed to load .*spec/app\.rb; removing partially defined constants\z},
177
+ "Removed constant App",
178
+ %r{\ALoading.*spec/app\.rb\z},
179
+ %r{\ANew classes in .*spec/app\.rb: App\z}
180
+ end
181
+
160
182
  it "should unload classes in namespaces" do
161
183
  ru(:code=>"class Array::App; def self.call(env) @a end; @a ||= []; @a << 1; end", :block=>proc{Array::App}).call({}).must_equal [1]
162
184
  update_app("class Array::App; def self.call(env) @a end; @a ||= []; @a << 2; end")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-unreloader
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-24 00:00:00.000000000 Z
11
+ date: 2019-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -84,8 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
- rubyforge_project:
88
- rubygems_version: 2.6.8
87
+ rubygems_version: 3.0.3
89
88
  signing_key:
90
89
  specification_version: 4
91
90
  summary: Reload application when files change, unloading constants first