Rails无效字节运行任何脚本

时间:2012-02-02 01:51:48

标签: ruby-on-rails postgresql utf-8

似乎无法想出这个,试图运行任何脚本我得到这个错误:
invalid byte sequence in UTF-8 (ArgumentError)

我有一台新的OS X机器,一切都很新鲜,使用Ruby 1.9.3和Rails 3.2.1,我已经开发了几天没有问题。

我今天离开了几个小时,现在我无法运行任何脚本。

我第一次尝试新迁移时遇到错误,认为这是Postgres的问题,重新安装,确保所有表都使用UTF-8进行编码。

我还重新安装了RVM和Rails。

我认为如果它与数据库有关,调试会更容易,但是我创建了新的应用程序,甚至无法启动服务器,收到同样的错误。

尝试在sqlite3上的新应用程序中运行服务器的完整堆栈


/Users/mgaughan/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:136:in `split': invalid byte sequence in UTF-8 (ArgumentError)
    from /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:136:in `setup_environment'
    from /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler/runtime.rb:13:in `setup'
    from /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler.rb:110:in `setup'
    from /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0@global/gems/bundler-1.0.21/lib/bundler/setup.rb:7:in `'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `require'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
    from /Users/mgaughan/Code/something/config/boot.rb:6:in `'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from script/rails:5:in `'

现在我看的越多,显然有一些东西搞砸了postgresql,因为在postgresql上的应用程序中,bundle失败了安装pg

堆栈追踪:


Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb 
checking for pg_config... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
    --with-pg
    --without-pg
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
/Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:1357:in `split': invalid byte sequence in UTF-8 (ArgumentError)
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:1357:in `find_executable0'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:1384:in `block in find_executable'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /Users/mgaughan/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/mkmf.rb:1383:in `find_executable'
    from extconf.rb:27:in `'


Gem files will remain installed in /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0/gems/pg-0.12.2 for inspection.
Results logged to /Users/mgaughan/.rvm/gems/ruby-1.9.3-p0/gems/pg-0.12.2/ext/gem_make.out
An error occured while installing pg (0.12.2), and Bundler cannot continue.
Make sure that `gem install pg -v '0.12.2'` succeeds before bundling.

它提到检查的mkmf.log文件是空白的。

所以我猜测Postgresql可能是这个问题的根源,但我很难理解为什么使用sqlite3的新应用程序仍会抛出此字节错误。

任何帮助都将不胜感激,如果我能提供更多信息,请告诉我。

修改

这个问题似乎已经解决了。

我制作的机器的唯一变化是@Frederick Cheung建议的;我从我的Path中删除了一个sbin文件夹,该文件夹来自已卸载的旧NGINX安装。

可能这是差异,但对我来说似乎不太可能。

无论如何,我跑了一个命令,一切都很好,已经好几天了。

2 个答案:

答案 0 :(得分:1)

根据堆栈跟踪判断,PATH环境变量包含一些令人讨厌的数据。我首先检查它并删除看起来不属于它的任何东西

答案 1 :(得分:0)

您的任何初始化程序或环境配置(application.rb,development.rb等)是否包含无效字符?

如果您从网上抓取了一个javascript文件,并且标题中有时髦的字符,通常会发生这种情况。如果将它包含在application.js中,则Sprockets解析器会对其进行抖动。

在这种情况下,看起来就像是在尝试运行你的应用程序时,所以它告诉我在初始化过程中使用的其中一个文件中是无效字符。