Segmentation fault (core dumped)
每当我运行我的 Sinatra 应用程序并SystemStackError stack level too deep
尝试加载索引页面时,我都会得到一个。它立即关闭应用服务器(瘦)。我无法弄清楚我哪里出错了,也找不到任何类似的错误。Sinatra Assetpack 似乎有问题。当我注释掉 layout.haml 文件中的行时,我没有收到此错误。这是我的主要应用程序文件:
require 'sinatra'
require 'sinatra/activerecord'
require 'alphadecimal'
require 'sinatra/assetpack'
require 'less'
require 'haml'
#App files
require File.join(File.dirname(__FILE__), 'settings.rb') #Database
class UberUrlShortener < Sinatra::Base
set :root, File.dirname(__FILE__)
#Less.paths << "#{UberUrlShortener.root}/app/css"
register Sinatra::AssetPack
enable :inline_templates
assets do
serve '/js', from: 'app/js' # Default
serve '/css', from: 'app/css' # Default
serve '/images', from: 'app/images' # Default
# Add all the paths that Less should look in for @import'ed files
css :app, '/css/app.css', [
# '/css/bootstrap.css', # bootstrap.less
'/css/*.css',
'/css/*.min.css'
]
js :app, '/js/app.js', [
'/js/*.js'
]
css_compression :simple
js_compression :jsmin
end
#Routes Controller
get '/' do
haml :index
end
post '/' do
@short_url = ShortenedUrl.find_or_create_by_url(params[:url])
if @short_url.valid?
haml :success
else
haml :index
end
end
get '/:shortened' do
short_url = ShortenedUrl.find_by_shortened(params[:shortened])
redirect short_url.url
end
run! if app_file == $0
end
#Model. Later could be seperate file
class ShortenedUrl < ActiveRecord::Base
validates_uniqueness_of :url
validates_presence_of :url
validates_format_of :url, :with => URI::regexp(%w(http))
def shorten
self.id.alphadecimal
end
def self.find_by_shortened(shortened)
find(shortened.alphadecimal)
end
end
这是我的 index.haml 文件:
%form(action="/" method="POST")
%label(for="url")
%input(type="text" name="url" id="url")
%input(type="submit" value="Shorten")
-if @short_url.present? && !@short_url.valid?
%p Invalid URL: #{@short_url.url}
这是我的 layout.haml 文件:
!!!
%html
%head
%meta{:charset => 'utf-8'}
%title Uber URL Shortener
%meta{:name => 'description', :content => 'URL Shortner for Uber Digital Agency'}
%meta{:name => 'author', :content => 'Cody Littlewood'}
:plain
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
/Le styles
!=css :app
!=js :app
%body= yield
这是我的 Gemfile:
source 'https://rubygems.org'
gem "sinatra", "~> 1.4.3", :require => 'sinatra/base'
gem 'thin', '~> 1.5.1' #decide on
gem 'pg', '~> 0.16.0'
gem 'alphadecimal', '1.1.2'
gem 'sinatra-assetpack', '~> 0.2.8'
gem 'haml', '~> 4.0.3'
gem 'less', '~> 2.3.2'
gem 'json', '~> 1.8.0'
gem 'therubyracer', '~> 0.11.4'
这是使用调试运行时的错误:
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
./views/index.haml:-5: warning: instance variable @haml_buffer not initialized
./views/index.haml:5: warning: instance variable @short_url not initialized
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/configurator.rb:13: warning: instance variable @asset_hosts not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @silent not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @trace not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @silent not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @trace not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @silent not initialized
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/thin-1.5.1/lib/thin/logging.rb:13: warning: instance variable @trace not initialized
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/engines/simple.rb:4: warning: ambiguous first argument; put parentheses or even spaces
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/engines/sqwish.rb:11: warning: assigned but unused variable - e
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
/home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-assetpack-0.2.8/lib/sinatra/assetpack/engines/uglify.rb:6: warning: assigned but unused variable - e
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001ba4e28>
Exception `NoMethodError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb:1879 - undefined method `to_ary' for #<Gem::Specification:0x00000001c39398>
Exception `SystemStackError' at /home/codelitt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/uri/common.rb:150 - stack level too deep
Exception `SystemStackError' at /home/codelitt/.rvm/gems/ruby-2.0.0-p247/gems/sinatra-1.4.3/lib/sinatra/base.rb:1087 - stack level too deep
Segmentation fault (core dumped)