New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable just digest-named templates to show error pages #7

Closed
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@tkawa

tkawa commented Nov 12, 2016

Running assets:precompile sometimes fails with Gakubuchi.
cf. http://docs.komagata.org/5407

I'm doubtful about the rake task after assets:precompile but it is not clear yet.
To avoid running the rake task, I introduce a special exceptions app as Gakubuchi::PublicException that allows digest-named templates (like public/assets/404-*.html.slim) themselves to show error pages. I also introduce a configuration option to switch whether to run the task.

This solution can be applied only in the case of error pages, but I think this is still useful.

view_context.asset_digest_path("#{status}.html")
if digest_path
path = File.join(public_path, view_context.assets_prefix, digest_path)
render_format(status, 'text/html', File.read(path))

This comment has been minimized.

@yasaichi

yasaichi Nov 12, 2016

Owner

[rubocop]

  • Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. :ref
@yasaichi

yasaichi Nov 12, 2016

Owner

[rubocop]

  • Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. :ref
@yasaichi

This comment has been minimized.

Show comment
Hide comment
@yasaichi

yasaichi Nov 13, 2016

Owner

@tkawa
Thanks for your pull request 🙇
Although I didn't know how capistrano deployed an app well, perhaps I was able to find how to reproduce the error.
Here is the procedure:

  1. cd spec/dummy
  2. Comment out config.assets.js_compressor = :uglifier in spec/dummy/config/environments/production.rb
  3. Execute RAILS_ENV=production bundle exec rake assets:precompile
  4. Change some lines of any templates (e.g. spec/dummy/app/assets/templates/foo.html.erb)
  5. Re-execute asstets precompile twice

Then, you'll get the following error like what the blog author got:

I, [2016-11-13T21:09:07.940530 #47120]  INFO -- : Removed /path/to/gakubuchi/spec/dummy/public/assets/bar/baz-904e18cda17e190f1219ce3b204b450fda5f7fd91ffed054a575ca75a9540ce2.html /path/to/gakubuchi/spec/dummy/public/assets/bar/baz-904e18cda17e190f1219ce3b204b450fda5f7fd91ffed054a575ca75a9540ce2.html.gz
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /path/to/gakubuchi/spec/dummy/public/assets/foo-889aac4cd7567398b3512cf05e726cb6b3f1fccdb87958358e6b286b708a85a4.html
/path/to/gakubuchi/lib/gakubuchi/fileutils.rb:8:in `copy_p'
/path/to/gakubuchi/lib/gakubuchi/task.rb:15:in `block in execute!'
/path/to/gakubuchi/lib/gakubuchi/task.rb:10:in `each'
/path/to/gakubuchi/lib/gakubuchi/task.rb:10:in `execute!'
/path/to/gakubuchi/lib/tasks/after_precompile.rake:3:in `block in <top (required)>'
/usr/local/var/rbenv/versions/2.3.1/gemsets/gakubuchi/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/usr/local/var/rbenv/versions/2.3.1/bin/bundle:23:in `load'
/usr/local/var/rbenv/versions/2.3.1/bin/bundle:23:in `<main>'

And the manifest file is as follows:

{"files":{"application-f9d8e5ce8f528d997d58156ff5f8c1d4b0741ac22b367a6a6294b3c7e9758e96.js":{"logical_path":"application.js","mtime":"2015-08-13T22:38:44+09:00","size":580,"digest":"f9d8e5ce8f528d997d58156ff5f8c1d4b0741ac22b367a6a6294b3c7e9758e96","integrity":"sha256-+djlzo9SjZl9WBVv9fjB1LB0GsIrNnpqYpSzx+l1jpY="},"application-e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113.css":{"logical_path":"application.css","mtime":"2015-08-13T22:38:44+09:00","size":653,"digest":"e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113","integrity":"sha256-6A6PIxgEPor5Td3Cra1aTwlzmo67Mjs6sxzXHUX9kRM="},"bar/baz-904e18cda17e190f1219ce3b204b450fda5f7fd91ffed054a575ca75a9540ce2.html":{"logical_path":"bar/baz.html","mtime":"2015-08-13T22:38:44+09:00","size":420,"digest":"904e18cda17e190f1219ce3b204b450fda5f7fd91ffed054a575ca75a9540ce2","integrity":"sha256-kE4YzaF+GQ8SGc47IEtFD9pff9kf/tBUpXXKdalUDOI="},"foo-889aac4cd7567398b3512cf05e726cb6b3f1fccdb87958358e6b286b708a85a4.html":{"logical_path":"foo.html","mtime":"2016-11-13T20:42:42+09:00","size":412,"digest":"889aac4cd7567398b3512cf05e726cb6b3f1fccdb87958358e6b286b708a85a4","integrity":"sha256-iJqsTNdWc5izUSzwXnJstrPx/M24eVg1jmsoa3CKhaQ="},"quux-5c92ce0571f858c83411a476f68107e3726a80445f5bfafd6f6521fda2b84737.html":{"logical_path":"quux.html","mtime":"2015-08-13T22:38:44+09:00","size":397,"digest":"5c92ce0571f858c83411a476f68107e3726a80445f5bfafd6f6521fda2b84737","integrity":"sha256-XJLOBXH4WMg0EaR29oEH43JqgERfW/r9b2Uh/aK4Rzc="},"qux-1eefb5cd3a99b9ed8ace7b57bf89c0fdba02f184bb4deacc19f91ad5565077e2.html":{"logical_path":"qux.html","mtime":"2015-08-13T22:38:44+09:00","size":502,"digest":"1eefb5cd3a99b9ed8ace7b57bf89c0fdba02f184bb4deacc19f91ad5565077e2","integrity":"sha256-Hu+1zTqZue2KzntXv4nA/boC8YS7TerMGfka1VZQd+I="},"foo-9ae9615355bc768d3b5dda5dafe0f72e8df2bc87b29d52758bc9cbc846823ad3.html":{"logical_path":"foo.html","mtime":"2016-11-13T20:44:12+09:00","size":411,"digest":"9ae9615355bc768d3b5dda5dafe0f72e8df2bc87b29d52758bc9cbc846823ad3","integrity":"sha256-mulhU1W8do07Xdpdr+D3Lo3yvIeynVJ1i8nLyEaCOtM="}},"assets":{"application.js":"application-f9d8e5ce8f528d997d58156ff5f8c1d4b0741ac22b367a6a6294b3c7e9758e96.js","application.css":"application-e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113.css","bar/baz.html":"bar/baz-904e18cda17e190f1219ce3b204b450fda5f7fd91ffed054a575ca75a9540ce2.html","foo.html":"foo-9ae9615355bc768d3b5dda5dafe0f72e8df2bc87b29d52758bc9cbc846823ad3.html","quux.html":"quux-5c92ce0571f858c83411a476f68107e3726a80445f5bfafd6f6521fda2b84737.html","qux.html":"qux-1eefb5cd3a99b9ed8ace7b57bf89c0fdba02f184bb4deacc19f91ad5565077e2.html"}}
Owner

yasaichi commented Nov 13, 2016

@tkawa
Thanks for your pull request 🙇
Although I didn't know how capistrano deployed an app well, perhaps I was able to find how to reproduce the error.
Here is the procedure:

  1. cd spec/dummy
  2. Comment out config.assets.js_compressor = :uglifier in spec/dummy/config/environments/production.rb
  3. Execute RAILS_ENV=production bundle exec rake assets:precompile
  4. Change some lines of any templates (e.g. spec/dummy/app/assets/templates/foo.html.erb)
  5. Re-execute asstets precompile twice

Then, you'll get the following error like what the blog author got:

I, [2016-11-13T21:09:07.940530 #47120]  INFO -- : Removed /path/to/gakubuchi/spec/dummy/public/assets/bar/baz-904e18cda17e190f1219ce3b204b450fda5f7fd91ffed054a575ca75a9540ce2.html /path/to/gakubuchi/spec/dummy/public/assets/bar/baz-904e18cda17e190f1219ce3b204b450fda5f7fd91ffed054a575ca75a9540ce2.html.gz
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /path/to/gakubuchi/spec/dummy/public/assets/foo-889aac4cd7567398b3512cf05e726cb6b3f1fccdb87958358e6b286b708a85a4.html
/path/to/gakubuchi/lib/gakubuchi/fileutils.rb:8:in `copy_p'
/path/to/gakubuchi/lib/gakubuchi/task.rb:15:in `block in execute!'
/path/to/gakubuchi/lib/gakubuchi/task.rb:10:in `each'
/path/to/gakubuchi/lib/gakubuchi/task.rb:10:in `execute!'
/path/to/gakubuchi/lib/tasks/after_precompile.rake:3:in `block in <top (required)>'
/usr/local/var/rbenv/versions/2.3.1/gemsets/gakubuchi/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/usr/local/var/rbenv/versions/2.3.1/bin/bundle:23:in `load'
/usr/local/var/rbenv/versions/2.3.1/bin/bundle:23:in `<main>'

And the manifest file is as follows:

{"files":{"application-f9d8e5ce8f528d997d58156ff5f8c1d4b0741ac22b367a6a6294b3c7e9758e96.js":{"logical_path":"application.js","mtime":"2015-08-13T22:38:44+09:00","size":580,"digest":"f9d8e5ce8f528d997d58156ff5f8c1d4b0741ac22b367a6a6294b3c7e9758e96","integrity":"sha256-+djlzo9SjZl9WBVv9fjB1LB0GsIrNnpqYpSzx+l1jpY="},"application-e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113.css":{"logical_path":"application.css","mtime":"2015-08-13T22:38:44+09:00","size":653,"digest":"e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113","integrity":"sha256-6A6PIxgEPor5Td3Cra1aTwlzmo67Mjs6sxzXHUX9kRM="},"bar/baz-904e18cda17e190f1219ce3b204b450fda5f7fd91ffed054a575ca75a9540ce2.html":{"logical_path":"bar/baz.html","mtime":"2015-08-13T22:38:44+09:00","size":420,"digest":"904e18cda17e190f1219ce3b204b450fda5f7fd91ffed054a575ca75a9540ce2","integrity":"sha256-kE4YzaF+GQ8SGc47IEtFD9pff9kf/tBUpXXKdalUDOI="},"foo-889aac4cd7567398b3512cf05e726cb6b3f1fccdb87958358e6b286b708a85a4.html":{"logical_path":"foo.html","mtime":"2016-11-13T20:42:42+09:00","size":412,"digest":"889aac4cd7567398b3512cf05e726cb6b3f1fccdb87958358e6b286b708a85a4","integrity":"sha256-iJqsTNdWc5izUSzwXnJstrPx/M24eVg1jmsoa3CKhaQ="},"quux-5c92ce0571f858c83411a476f68107e3726a80445f5bfafd6f6521fda2b84737.html":{"logical_path":"quux.html","mtime":"2015-08-13T22:38:44+09:00","size":397,"digest":"5c92ce0571f858c83411a476f68107e3726a80445f5bfafd6f6521fda2b84737","integrity":"sha256-XJLOBXH4WMg0EaR29oEH43JqgERfW/r9b2Uh/aK4Rzc="},"qux-1eefb5cd3a99b9ed8ace7b57bf89c0fdba02f184bb4deacc19f91ad5565077e2.html":{"logical_path":"qux.html","mtime":"2015-08-13T22:38:44+09:00","size":502,"digest":"1eefb5cd3a99b9ed8ace7b57bf89c0fdba02f184bb4deacc19f91ad5565077e2","integrity":"sha256-Hu+1zTqZue2KzntXv4nA/boC8YS7TerMGfka1VZQd+I="},"foo-9ae9615355bc768d3b5dda5dafe0f72e8df2bc87b29d52758bc9cbc846823ad3.html":{"logical_path":"foo.html","mtime":"2016-11-13T20:44:12+09:00","size":411,"digest":"9ae9615355bc768d3b5dda5dafe0f72e8df2bc87b29d52758bc9cbc846823ad3","integrity":"sha256-mulhU1W8do07Xdpdr+D3Lo3yvIeynVJ1i8nLyEaCOtM="}},"assets":{"application.js":"application-f9d8e5ce8f528d997d58156ff5f8c1d4b0741ac22b367a6a6294b3c7e9758e96.js","application.css":"application-e80e8f2318043e8af94dddc2adad5a4f09739a8ebb323b3ab31cd71d45fd9113.css","bar/baz.html":"bar/baz-904e18cda17e190f1219ce3b204b450fda5f7fd91ffed054a575ca75a9540ce2.html","foo.html":"foo-9ae9615355bc768d3b5dda5dafe0f72e8df2bc87b29d52758bc9cbc846823ad3.html","quux.html":"quux-5c92ce0571f858c83411a476f68107e3726a80445f5bfafd6f6521fda2b84737.html","qux.html":"qux-1eefb5cd3a99b9ed8ace7b57bf89c0fdba02f184bb4deacc19f91ad5565077e2.html"}}
@yasaichi

This comment has been minimized.

Show comment
Hide comment
@yasaichi

yasaichi Nov 13, 2016

Owner

@tkawa
As you can see the procedure and error, it seems caused by the former .sprockets-manifest-*.json.
Therefore, I think it is possible to solve the error by just fixing Gakubuchi::Template#digest_path, not using exceptions_app.

Owner

yasaichi commented Nov 13, 2016

@tkawa
As you can see the procedure and error, it seems caused by the former .sprockets-manifest-*.json.
Therefore, I think it is possible to solve the error by just fixing Gakubuchi::Template#digest_path, not using exceptions_app.

@tkawa

This comment has been minimized.

Show comment
Hide comment
@tkawa

tkawa Nov 14, 2016

Therefore, I think it is possible to solve the error by just fixing Gakubuchi::Template#digest_path, not using exceptions_app.

That sounds great. Is view_context likely to be harmful? I'm not sure...
I hope we find out the solution.

This problem occurs in spite of my using not capistrano but Heroku, if that helps.

tkawa commented Nov 14, 2016

Therefore, I think it is possible to solve the error by just fixing Gakubuchi::Template#digest_path, not using exceptions_app.

That sounds great. Is view_context likely to be harmful? I'm not sure...
I hope we find out the solution.

This problem occurs in spite of my using not capistrano but Heroku, if that helps.

@yasaichi

This comment has been minimized.

Show comment
Hide comment
@yasaichi

yasaichi Nov 14, 2016

Owner

@tkawa

This problem occurs in spite of my using not capistrano but Heroku, if that helps.

It was so helpful that I could probably fix the bug!
Could you please try the following branch? 🙇
https://github.com/yasaichi/gakubuchi/tree/fix-precompile-bug-when-disabling-fallback

Owner

yasaichi commented Nov 14, 2016

@tkawa

This problem occurs in spite of my using not capistrano but Heroku, if that helps.

It was so helpful that I could probably fix the bug!
Could you please try the following branch? 🙇
https://github.com/yasaichi/gakubuchi/tree/fix-precompile-bug-when-disabling-fallback

@tkawa

This comment has been minimized.

Show comment
Hide comment
@tkawa

tkawa Nov 15, 2016

With the fix-precompile-bug-when-disabling-fallback branch, I have successfully deployed a certain app several times to Heroku. I think this fix probably goes well.
Thanks for your fine investigation!

tkawa commented Nov 15, 2016

With the fix-precompile-bug-when-disabling-fallback branch, I have successfully deployed a certain app several times to Heroku. I think this fix probably goes well.
Thanks for your fine investigation!

@yasaichi

This comment has been minimized.

Show comment
Hide comment
@yasaichi

yasaichi Nov 15, 2016

Owner

@tkawa
I'm glad the branch works well!
I'll close this PR because I've merged and released it as v1.2.3 🙇

Owner

yasaichi commented Nov 15, 2016

@tkawa
I'm glad the branch works well!
I'll close this PR because I've merged and released it as v1.2.3 🙇

@yasaichi yasaichi closed this Nov 15, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment