f10a
f10a

Reputation: 51

rake aborted! JSON::GeneratorError: source sequence is illegal/malformed utf-8 after rake assets:precompile

I finished building a website and want to deploy it to Digital Ocean VPN. Installed Capistrano and Passenger. During initial deployment I was receiving an error that apparently had to do with precompiling assets, so I tried "rake assets:precompile --trace RAILS_ENV=production" in my rails production environment locally and the process is aborted with this message: "JSON::GeneratorError: source sequence is illegal/malformed utf-8" Can anyone help me with this, I can't seem to be able to fix this.

> rake aborted! JSON::GeneratorError: source sequence is
> illegal/malformed utf-8
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/json-1.8.3/lib/json/common.rb:223:in
> `generate'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/json-1.8.3/lib/json/common.rb:223:in
> `generate'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/execjs-2.5.2/lib/execjs/external_runtime.rb:46:in
> `call'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/uglifier-2.7.1/lib/uglifier.rb:212:in
> `run_uglifyjs'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/uglifier-2.7.1/lib/uglifier.rb:179:in
> `compile'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/uglifier_compressor.rb:52:in `call'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/uglifier_compressor.rb:28:in `call'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:75:in
> `call_processor'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:57:in
> `block in call_processors'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:56:in
> `reverse_each'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:56:in
> `call_processors'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/loader.rb:86:in
> `load_asset_by_uri'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/loader.rb:45:in
> `block in load'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/loader.rb:155:in
> `fetch_asset_from_dependency_cache'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/loader.rb:38:in
> `load'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:20:in
> `block in initialize'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:47:in
> `yield'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:47:in
> `load'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/base.rb:63:in
> `find_asset'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/base.rb:70:in
> `find_all_linked_assets'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:138:in
> `block in find'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:114:in
> `block (2 levels) in logical_paths'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:223:in
> `block in stat_tree'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:207:in
> `block in stat_directory'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:204:in
> `each'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:204:in
> `stat_directory'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:222:in
> `stat_tree'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:105:in
> `each'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:105:in
> `block in logical_paths'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:104:in
> `each'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:104:in
> `logical_paths'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:136:in
> `find'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:162:in
> `compile'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:70:in
> `block (3 levels) in define'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-3.2.0/lib/rake/sprocketstask.rb:147:in
> `with_logger'
> /Users/franco/.rvm/gems/ruby-2.2.2/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:69:in
> `block (2 levels) in define'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:240:in
> `call'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:240:in
> `block in execute'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:235:in
> `each'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:235:in
> `execute'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:179:in
> `block in invoke_with_call_chain'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in
> `mon_synchronize'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:172:in
> `invoke_with_call_chain'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/task.rb:165:in
> `invoke'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:150:in
> `invoke_task'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in
> `block (2 levels) in top_level'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in
> `each'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in
> `block in top_level'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:115:in
> `run_with_threads'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:100:in
> `top_level'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:78:in
> `block in run'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in
> `standard_exception_handling'
> /Users/franco/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in
> `run' /Users/franco/.rvm/rubies/ruby-2.2.2/bin/rake:33:in `<main>'
> Tasks: TOP => assets:precompile

Upvotes: 4

Views: 3062

Answers (1)

burnabyRails
burnabyRails

Reputation: 402

I encountered the exactly same error message. With that telltale, I googled "check if a file is valid utf-8" and found isutf8(1): check whether files are valid UTF-8 - Linux man page. So I installed isutf8 and then ran the following command from the Rails root on my linux machine

isutf8 `find app`

Although there are lots of noise in the output, it tells me that app/assets/javascripts/filterbar.js: line 1, char 1, byte offset 41: invalid UTF-8 code. So I opened that file. Viola! I saw a few garbled characters. Once I removed those characters, my rake assets:precompile succeeded. The actual guilty file of yours might be different, of course. You can also use other utility to check utf-8 such as in this stackoverflow question on utf-8, of course.

Upvotes: 4

Related Questions