由于JSON :: Generator错误,无法使用Capistrano部署到Digital Ocean VPS:源序列非法/格式错误utf-8

时间:2016-03-24 09:26:47

标签: ruby-on-rails-4 vps capistrano3

我已经搜索了几个小时来解决这个问题而无济于事。我似乎无法解决这个问题。

  

* cap production deploy *会抛出以下错误,如日志中所示。   这solution无济于事。

    Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@xxx.xxx.xx.xxx: rake exit status: 1
rake stdout: rake aborted!
JSON::GeneratorError: source sequence is illegal/malformed utf-8
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/json-1.8.3/lib/json/common.rb:223:in `generate'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/json-1.8.3/lib/json/common.rb:223:in `generate'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:46:in `call'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/uglifier-2.7.2/lib/uglifier.rb:212:in `run_uglifyjs'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/uglifier-2.7.2/lib/uglifier.rb:179:in `compile'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/uglifier_compressor.rb:52:in `call'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/uglifier_compressor.rb:28:in `call'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/processor_utils.rb:75:in `call_processor'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/processor_utils.rb:56:in `call_processors'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/loader.rb:60:in `block in load'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/loader.rb:44:in `load'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/cached_environment.rb:47:in `yield'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/cached_environment.rb:47:in `load'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/base.rb:66:in `find_asset'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/manifest.rb:138:in `block in find'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/path_utils.rb:223:in `block in stat_tree'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/path_utils.rb:207:in `block in stat_directory'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/path_utils.rb:204:in `each'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/path_utils.rb:204:in `stat_directory'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/path_utils.rb:222:in `stat_tree'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/legacy.rb:105:in `each'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/legacy.rb:104:in `each'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/legacy.rb:104:in `logical_paths'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/manifest.rb:136:in `find'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/sprockets/manifest.rb:162:in `compile'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-3.4.0/lib/rake/sprocketstask.rb:147:in `with_logger'
/var/www/html/app/shared/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
rake stderr: Nothing written


  [1]: https://stackoverflow.com/questions/31372478/rake-aborted-jsongeneratorerror-source-sequence-is-illegal-malformed-utf-8-a

我耐心等待解决方案

1 个答案:

答案 0 :(得分:0)

正在编译的一个JS文件包含无效的UTF-8字节。我不知道哪一个,但我建议你调试的方法是在本地编辑/var/www/html/app/shared/bundle/ruby/2.2.0/gems/json-1.8.3/lib/json/common.rb:223:in generate'的等效路径,将破解调用包装在一个块中:

begin
  # Whatever normally goes here.
rescue JSON::GeneratorError
  puts whateverliststhefilename
end

如果您已经在使用此功能,那么您也可以放入binding.pry而不是放置。

知道文件名后,通过UTF-8验证器运行它,就像你在链接的SO答案中看到的那样,并修复它。如果JS在gem中,请尝试将gem恢复到原始状态。如果JS在您的项目中,请相应地修复它。

您可以使用http://guides.rubygems.org/command-reference/#gem-pristine恢复已修改或损坏的gem。完成后,请务必从gem文件中删除调试代码。

这更像是一个教导如何捕鱼答案而不是“这是什么错误以及如何解决它”的答案。对此感到抱歉,但我们无法做到这一点,除非它是宝石中一个众所周知的问题,Google搜索会提出这个问题,或者我们有完整的源代码。

希望这有帮助!