2011-06-13 81 views
24

在Ruby 1.9.2堆栈跟踪中,我经常看到给出的方法为<top (required)>,如下面的堆栈本节所述。这是什么意思?我的Ruby安装是否微妙破碎?“<top(required)>”在Ruby堆栈跟踪中意味着什么?

Could not find abstract-1.0.0 in any of the sources 
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:87:in `block in materialize' 
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in `map!' 
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/spec_set.rb:81:in `materialize' 
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:90:in `specs' 
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:135:in `specs_for' 
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/definition.rb:124:in `requested_specs' 
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/environment.rb:23:in `requested_specs' 
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/runtime.rb:11:in `setup' 
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler.rb:107:in `setup' 
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.0.13/lib/bundler/setup.rb:14:in `<top (required)>' 
<internal:lib/rubygems/custom_require>:33:in `require' 
<internal:lib/rubygems/custom_require>:33:in `rescue in require' 
<internal:lib/rubygems/custom_require>:29:in `require' 

回答

15

它是文件的顶层,即无论在需要文件时运行。
因此,如果在设置一个库期间失败(例如找不到某个需要的文件),它会像这样在堆栈跟踪中出现。

+1

所以“(必填)”部分意味着该文件已被处理,因为另一个文件用“require xxxxx”指定它,是吗? – iX3 2012-11-13 19:10:11

0

我在做“Jump Start Sinatra”一书中的教程时碰到了这个错误<top (required)>

我摆脱了错误,确保我运行了sudo gem install <GEM_IN_YOUR_FILE>。所以,在我的情况我有一个main.rb并在该文件我有这个

require 'sinatra' 
require 'sinatra-contrib' 

于是我又回到我的项目的根目录并运行sudo gem install sinatrasudo gem install sinatra-contrib,然后我的项目运行良好。

您的错误会有所不同,但因为这是我在Google上搜索时发现的,所以我知道其他人也会因为类似的原因来到这里。我提供这个解决方案,至少让你在正确的方向思考,因为这对我有效。

0

如果你需要的东西都是正确的,那可能意味着你正在尝试创建一个名称已经存在的模块类。例如以下文件:

class Test 
end 

将提高: <top (required)>': Test is not a class (TypeError)

因为测试是隐含的模块。

0

我有同样的问题。使用Notepad ++将.rb文件编码转换为UTF-8-BOM解决了这个问题。

相关问题