gpt4 book ai didi

ruby - 当我引发 RuntimeError 时,为什么 Sinatra 的 "show_exceptions.rb"文件会崩溃?

转载 作者:行者123 更新时间:2023-12-02 19:33:23 25 4
gpt4 key购买 nike

我有一个像这样简单的应用程序:

require "sinatra"

get "/" do
raise "Oops!"
end

由于这是一个调试环境,我希望看到“RuntimeError: Oops!”显示在浏览器中。相反,Sinatra 似乎正在崩溃:

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 37Web     GET 127.0.0.1/

控制台中的回溯:

RuntimeError - Oops!:    test.rb:5:in `block in '    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1603:in `block in compile!'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `[]'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (3 levels) in route!'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:985:in `route_eval'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:966:in `block (2 levels) in route!'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1006:in `block in process_route'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `catch'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1004:in `process_route'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:964:in `block in route!'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `each'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:963:in `route!'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1076:in `block in dispatch!'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1073:in `dispatch!'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `block in call!'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `block in invoke'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `catch'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1058:in `invoke'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:898:in `call!'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:886:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/rack-1.6.0.beta/lib/rack/logger.rb:15:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/rack-1.6.0.beta/lib/rack/commonlogger.rb:33:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:217:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:210:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/rack-1.6.0.beta/lib/rack/head.rb:13:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/rack-1.6.0.beta/lib/rack/methodoverride.rb:22:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/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/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:37:in `rescue in call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/show_exceptions.rb:21:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:180:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:2014:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `block in call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1788:in `synchronize'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/gems/sinatra-1.4.5/lib/sinatra/base.rb:1478:in `call'    /home/tomas/.rvm/gems/ruby-2.0.0-p481@test/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

这对我来说完全没有帮助。这是怎么回事?

最佳答案

它看起来像 recent change in Rack在 Sinatra 中引入了这个错误,has been fixed但该修复尚未(在撰写本文时)包含在版本中。

最简单的修复(直到更新的 Sinatra gem 发布)是使用早期版本的 Rack(目前仅在 1.6.0.beta 中进行了更改)。如果您使用的是 Bundler,请将此行添加到您的 Gemfile 中;如果您没有使用 Bundler,请将此行添加到脚本开头附近的位置(在 require 任何内容之前):

gem 'rack', '1.5.2'

关于ruby - 当我引发 RuntimeError 时,为什么 Sinatra 的 "show_exceptions.rb"文件会崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26255022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com