Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails debug assets:precompile: how to identify offending file(s)?

I'm a bit desperate; been trying to debug this problem for days. ANYONE have any idea how to troubleshoot? Perhaps identify the file(s) that are creating the encoding problem?

FWIW: This works in dev environment: RAILS_ENV=production bundle exec rake assets:precompile --trace

But this fails on 'production' server...no idea how to begin troubleshooting:

$ RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
I, [2013-09-26T10:54:13.904512 #8431]  INFO -- : Writing /rails/myapp/releases/20130926175008/public/assets/sort_asc-9348a2efdfbcfa28135e10d4f7b42d0d.png
I, [2013-09-26T10:54:13.945109 #8431]  INFO -- : Writing /rails/myapp/releases/20130926175008/public/assets/sort_asc_disabled-30ae6b96c67982047ca4cfa0b8ce81b2.png
I, [2013-09-26T10:54:14.007435 #8431]  INFO -- : Writing /rails/myapp/releases/20130926175008/public/assets/sort_both-8018c940cc83bb4cf2bf0e68e41fdcc0.png
I, [2013-09-26T10:54:14.011733 #8431]  INFO -- : Writing /rails/myapp/releases/20130926175008/public/assets/sort_desc-05521e27371d9dd4e6febce9314bc7ed.png
I, [2013-09-26T10:54:14.017370 #8431]  INFO -- : Writing /rails/myapp/releases/20130926175008/public/assets/sort_desc_disabled-a3215e17d6bf077db02468b895fee228.png
rake aborted!
Caught Encoding::CompatibilityError at '["ok","!function(e,t': incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)
  (in /rails/myapp/releases/20130926175008/app/assets/javascripts/application.js)
/rails/myapp/shared/bundle/ruby/2.0.0/gems/json-1.8.0/lib/json/pure/parser.rb:242:in `rescue in parse_string'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/json-1.8.0/lib/json/pure/parser.rb:213:in `parse_string'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/json-1.8.0/lib/json/pure/parser.rb:257:in `parse_value'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/json-1.8.0/lib/json/pure/parser.rb:121:in `parse'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/json-1.8.0/lib/json/common.rb:155:in `parse'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/json-1.8.0/lib/json/common.rb:334:in `load'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/execjs-2.0.1/lib/execjs/external_runtime.rb:62:in `extract_result'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/execjs-2.0.1/lib/execjs/external_runtime.rb:28:in `block in exec'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/execjs-2.0.1/lib/execjs/external_runtime.rb:41:in `compile_to_tempfile'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/execjs-2.0.1/lib/execjs/external_runtime.rb:27:in `exec'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/uglifier-2.2.1/lib/uglifier.rb:176:in `really_compile'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/uglifier-2.2.1/lib/uglifier.rb:100:in `compile'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/uglifier_compressor.rb:25:in `evaluate'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/context.rb:197:in `block in evaluate'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/context.rb:194:in `each'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/context.rb:194:in `evaluate'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/bundled_asset.rb:25:in `initialize'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:377:in `new'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:377:in `build_asset'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/index.rb:94:in `block in build_asset'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/caching.rb:58:in `cache_asset'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/index.rb:93:in `build_asset'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/base.rb:287:in `find_asset'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/index.rb:61:in `find_asset'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:211:in `block in find_asset'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:257:in `benchmark'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:210:in `find_asset'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:119:in `block in compile'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:118:in `each'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/sprockets/manifest.rb:118:in `compile'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.0/lib/sprockets/rails/task.rb:60:in `block (3 levels) in define'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-2.10.0/lib/rake/sprocketstask.rb:146:in `with_logger'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/sprockets-rails-2.0.0/lib/sprockets/rails/task.rb:59:in `block (2 levels) in define'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `call'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:236:in `block in execute'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `each'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:231:in `execute'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:175:in `block in invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:168:in `invoke_with_call_chain'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/task.rb:161:in `invoke'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:149:in `invoke_task'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/rails/myapp/shared/bundle/ruby/2.0.0/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/rails/myapp/shared/bundle/ruby/2.0.0/bin/rake:23:in `load'
/rails/myapp/shared/bundle/ruby/2.0.0/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile

Gemfile (as requested):

source 'https://rubygems.org'
ruby '2.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
gem 'pg'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'

group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

group :development, :test do
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'guard-rspec'
  # gem 'debugger'
end

group :development do
  gem 'annotate'
  gem 'spork-rails', github: 'sporkrb/spork-rails'
  gem 'guard-spork'
  gem 'awesome_print'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'pry-rails' #substitute pry for irb
end

group :test do
  gem 'selenium-webdriver'
  gem 'capybara'
  gem 'faker'
  gem 'database_cleaner'
  gem 'poltergeist'
  gem 'launchy'
end

gem 'rvm-capistrano' #, group: :development
gem 'haml-rails'
# gem 'zurb-foundation'
# gem 'foundicons-rails'
gem 'bootstrap-sass', :git => 'git://github.com/thomas-mcdonald/bootstrap-sass.git' #, :branch => '3'
gem 'kaminari'
gem 'ancestry'
gem 'twitter-typeahead-rails'
# gem 'bootstrap-typeahead-rails' #TODO
gem 'hogan_assets'
gem 'awesome_print'
gem 'multi_json', '1.7.8' # error in cap deploy with version 1.7.9
# gem 'json' # not necessary before multi_json deploy failure

gem 'textacular'
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
like image 901
Meltemi Avatar asked Sep 26 '13 18:09

Meltemi


People also ask

What does Rails assets Precompile do?

The Rails asset pipeline provides an assets:precompile rake task to allow assets to be compiled and cached up front rather than compiled every time the app boots. There are two ways you can use the asset pipeline on Heroku. Compiling assets locally.

What are sprockets Rails?

Sprockets is a Ruby library for compiling and serving web assets. Sprockets allows to organize an application's JavaScript files into smaller more manageable chunks that can be distributed over a number of directories and files.

What are assets in Rails?

Generally asset is anything that browser loads after it gets the HTML page. Meaning javascript, css and any images. But as you pointed out there are two different image types in a rails project.


2 Answers

I would just start a cycle of removing a file from your manifest, and then trying to deploy. If that didn't work, I'd remove the next file from the manifest, and so on until I found the one that was causing the issue.

like image 126
Jeremy Green Avatar answered Nov 09 '22 08:11

Jeremy Green


Just faced with similar issue - got InvalidByteSequenceError during assets:precompile. What I did was - I edited the sprockets gem code a bit to "puts" some debug info, current file name being processed in particular. Then I ran precompile again, found the file based on the debug output, and fixed it. Then of course I reverted gem changes. You can use the same approach since you have the backtrace. Moreover, you could even debug the asstes:precompile task (either by inline debugger or through your favourite IDE. Hope this helps!

like image 24
pokrovskyy Avatar answered Nov 09 '22 07:11

pokrovskyy