2014-10-08 40 views
7

我有如此簡單的應用程序:當我引發RuntimeError時,爲什麼Sinatra的「show_exceptions.rb」文件崩潰?

require "sinatra" 

get "/" do 
    raise "Oops!" 
end 

因爲這是一個調試環境,我希望看到一個「RuntimeError:哎呀呀」在瀏覽器中顯示。相反,它似乎西納特拉崩潰:

NoMethodError at/
undefined method `join' for #<String:0x00000002b74bf0> 

Ruby /home/tomas/.rvm/.../gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb: in rescue in call, line 37 
Web  GET 127.0.0.1/

回溯控制檯:

RuntimeError - Oops!: 
    test.rb:5:in `block in ' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-1.6.0.beta/lib/rack/logger.rb:15:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-1.6.0.beta/lib/rack/commonlogger.rb:33:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:217:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:210:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-1.6.0.beta/lib/rack/head.rb:13:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-1.6.0.beta/lib/rack/methodoverride.rb:22:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:89:in `service' 
    /home/tomas/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service' 
    /home/tomas/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run' 
    /home/tomas/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread' 
[2014-10-08 12:42:42] ERROR NoMethodError: undefined method `join' for #<String:0x007f52e055ce38> 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:37:in `rescue in call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize' 
    /home/tomas/.rvm/gems/[email protected]/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call' 
    /home/tomas/.rvm/gems/[email protected]/gems/rack-1.6.0.beta/lib/rack/handler/webrick.rb:89:in `service' 
    /home/tomas/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service' 
    /home/tomas/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run' 
    /home/tomas/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread' 
localhost - - [08/Oct/2014:12:42:42 CEST] "GET/HTTP/1.1" 500 340

這是完全無助於我。這裏發生了什麼?

回答

11

它看起來像一個recent change in Rack在Sinatra中引入了這個錯誤,其中has been fixed但修復程序沒有(在編寫本文時)包含在發行版中。

最簡單的修復方法(直到發佈更新的Sinatra寶石)將使用較早版本的Rack(該變化目前僅在1.6.0.beta中)。如果你使用的捆紮機,或某個腳本的開始接近這個行添加到您的Gemfile(之前require任何東西),如果你不:

gem 'rack', '1.5.2' 
+1

你說得對,先生 – Hubro 2014-10-08 11:54:09

+1

應當指出的是,在更新'Gemfile'後,'rackup'應該總是以'bundle exec rackup'運行,以確保正在使用相應版本的機架。 – 2015-02-01 14:32:46

相關問題