ruby-on-rails - 运行任何脚本的 Rails 无效字节

标签 ruby-on-rails postgresql utf-8

似乎无法解决这个问题,尝试运行任何脚本我都收到此错误:
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 安装。

可能这就是区别,但对我来说似乎不太可能。

无论如何,我运行了一条命令,一切正常,而且已经好几天了。

最佳答案

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

关于ruby-on-rails - 运行任何脚本的 Rails 无效字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9106058/

相关文章:

ruby-on-rails - Ruby 1.9.3 哈希语法不适用于 rspec-rails 2.9?

c++ - 在 Visual Studio 中链接 PostgreSQL 自定义 C++ 项目时出错

python - 在 Sqlalchemy/Postgres 中使用绑定(bind)参数执行 WHERE IN

sql - 从不同表的列更新表

mysql - 如何更改 MySQL 中每个表中每个字段的冲突?

Python,抓取 : bad utf8 characters writed in file from scraped html page with charset iso-8859-1

ruby-on-rails - 错误原始错误:未安装ImageMagick/GraphicsMagick

ruby-on-rails - 如何在 Ruby on Rails 中使用回形针使模型具有无限图像?

ruby-on-rails - 识别重复的电子邮件。在里面

csv - 文件使用多重编码