Explicit error when file exists but unreadable or not valid for some reason
From @pravi on April 11, 2015 19:56
see http://hackerheart.com/article/2013/02/undefined-method-directory-nilnilclass-while-compiling-rails-assets for sample code.
Copied from original issue: sstephenson/sprockets#714
From @schneems on August 28, 2015 17:22
If this is still an active issue can you close this one and re-open it at http://github.com/rails/sprockets. Active development has moved to that repo.
If you've got a bug with sprockets 3 please make sure you've tried the latest 3.3.3. If you can confirm this is still an active issue, the fastest way to get it fixed is to create a small example app that reproduces the failure and open an issue in the new repo http://github.com/rails/sprockets.
Link mentioning sample code is broken. Here is the archived link of same post.
Following error:
NoMethodError: undefined method `directory?' for nil:NilClass
seems to be stackoverflow category (1, 2, 3). Most common issue is broken symlink in assets folder or VMware sharing of files.
I guess it does make sense that sprockets should report missing file error with path instead of NoMethodError
However, I can't duplicate the issue with edge rails (sprockets 4.0.0 7c5ff2f ).
My application.css:
/*
*= require_self
*= require broken_link
*/
Create a broken symlink:
ln -s ~/i_do_not_exist.css app/assets/stylesheets/broken_link.css
Compile assets:
RAILS_ENV=production rake assets:precompile --trace
Error reported was:
Sprockets::FileNotFound: couldn't find file 'broken_link' with type 'text/css'
I tried limiting the access rights as well:
sudo chmod go-rwx app/assets/stylesheets/example.css
sudo chown git:git app/assets/stylesheets/example.css
Again error seemed to be valid:
Errno::EACCES: Permission denied @ rb_sysopen -path_to_app/edge_app/app/assets/stylesheets/example.scss
Here i'm getting a different error
Sprockets::FileNotFound: couldn't find file 'broken_link' with type 'text/css'
/Users/richardschneeman/Documents/projects/tmp/assets-blerg-169/foo/app/assets/config/manifest.js:3
/Users/richardschneeman/Documents/projects/tmp/assets-blerg-169/foo/app/assets/stylesheets/application.css:3
/Users/richardschneeman/Documents/projects/sprockets/lib/sprockets/resolve.rb:59:in `resolve!'
/Users/richardschneeman/Documents/projects/sprockets/lib/sprockets/directive_processor.rb:401:in `resolve'
/Users/richardschneeman/Documents/projects/sprockets/lib/sprockets/directive_processor.rb:208:in `process_require_directive'
/Users/richardschneeman/Documents/projects/sprockets/lib/sprockets/directive_processor.rb:181:in `block in process_directives'
/Users/richardschneeman/Documents/projects/sprockets/lib/sprockets/directive_processor.rb:179:in `each'
/Users/richardschneeman/Documents/projects/sprockets/lib/sprockets/directive_processor.rb:179:in `process_directives'
Using sprockets master.
We could add a special case check to see if the file exists but is unreadable or not valid for some other reason (permissions etc)
I'm going to keep this issue open but change the title. Original title "mention missing path when sprockets can't find an asset". We're already working on that, however if I view that path I see the broken_link.css file in my editor, a truly helpful error message would be to tell me why it's not valid.