Skip to content
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

Appends the load paths to error message #313

Merged
merged 2 commits into from Jun 22, 2016

Conversation

5minpause
Copy link
Contributor

When resolve! raises an error, it would not display the paths that
were used to look up the assets. If we raise this error we can be even
more helpful and display the config[:path] as well. This makes it
easier for users to debug their asset paths.

I am unsure whether you like the way I introduced the load paths into the error message. Please see below.

Original error messages:

ActionView::Template::Error (couldn't find file '../other_javascripts/f' under '/Users/holger/projects/ikusei/opensource/sprockets-test-app/app/assets/javascripts' with type 'application/javascript'):
    3: <head>
    4:   <title>SprocketsTestApp</title>
    5:   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    6:   <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    7:   <%= csrf_meta_tags %>
    8: </head>
    9: <body>
  app/assets/javascripts/application.js:20
  app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___2173404954647428090_70191239104980'


  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (5.9ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.4ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.7ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (54.1ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.3ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.2ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.4ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.3ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (50.5ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.3ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.4ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (109.3ms)

New error messages:

ActionView::Template::Error (couldn't find file '../other_javascripts/f' under '/Users/holger/projects/ikusei/opensource/sprockets-test-app/app/assets/javascripts' with type 'application/javascript'
Looked up these paths: ["/Users/holger/projects/ikusei/opensource/sprockets-test-app/app/assets/images", "/Users/holger/projects/ikusei/opensource/sprockets-test-app/app/assets/javascripts", "/Users/holger/projects/ikusei/opensource/sprockets-test-app/app/assets/other_javascripts", "/Users/holger/projects/ikusei/opensource/sprockets-test-app/app/assets/stylesheets", "/Users/holger/projects/ikusei/opensource/sprockets-test-app/lib/assets/javascripts", "/Users/holger/projects/ikusei/opensource/sprockets-test-app/vendor/assets/javascripts", "/Users/holger/projects/ikusei/opensource/sprockets-test-app/vendor/assets/stylesheets", "/Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/turbolinks-2.5.3/lib/assets/javascripts", "/Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/jquery-rails-4.1.0/vendor/assets/javascripts", "/Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/coffee-rails-4.1.1/lib/assets/javascripts"]):
    3: <head>
    4:   <title>SprocketsTestApp</title>
    5:   <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    6:   <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    7:   <%= csrf_meta_tags %>
    8: </head>
    9: <body>
  app/assets/javascripts/application.js:20
  app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___3948160733622279578_70177100816340'


  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (6.2ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (5.1ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.7ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-4.2.5.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (61.7ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.3ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.3ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.3ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (67.6ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.3ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.7ms)
  Rendered /Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (137.7ms)

I could not get the test to pass, because of the double escaping quotes:
Any help would be appreciated.

TestServer#test_"re-throw JS exceptions in the browser" [/Users/holger/projects/ikusei/opensource/sprockets/test/test_server.rb:244]:
--- expected
+++ actual
@@ -1,3 +1,3 @@
 "throw Error(\"Sprockets::FileNotFound: couldn't find file 'notfound' with type 'application/javascript'\
-Looked up these paths: [\"/Users/holger/projects/ikusei/opensource/sprockets/test/fixtures/server/app/javascripts\", \"/Users/holger/projects/ikusei/opensource/sprockets/test/fixtures/server/app/images\", \"/Users/holger/projects/ikusei/opensource/sprockets/test/fixtures/server/vendor/javascripts\", \"/Users/holger/projects/ikusei/opensource/sprockets/test/fixtures/server/vendor/stylesheets\"]\
+Looked up these paths: [\\\"/Users/holger/projects/ikusei/opensource/sprockets/test/fixtures/server/app/javascripts\\\", \\\"/Users/holger/projects/ikusei/opensource/sprockets/test/fixtures/server/app/images\\\", \\\"/Users/holger/projects/ikusei/opensource/sprockets/test/fixtures/server/vendor/javascripts\\\", \\\"/Users/holger/projects/ikusei/opensource/sprockets/test/fixtures/server/vendor/stylesheets\\\"]\
   (in /Users/holger/projects/ikusei/opensource/sprockets/test/fixtures/server/vendor/javascripts/missing_require.js:1)\")"

References #252

When `resolve!` raises an error, it would not display the paths that
were used to look up the assets. If we raise this error we can be even
more helpful and display the `config[:path]` as well. This makes it
easier for users to debug their asset paths.

References rails#252
@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rails-bot
Copy link

warning Warning warning

  • Pull requests are usually filed against the master branch for this repo, but this one is against 3.x. Please double check that you specified the right target!

@schneems
Copy link
Member

schneems commented Jun 17, 2016

I like the direction, i'm thinking that it's better to list out the paths like an ordered list. It might be a much longer error, but it will be more readable

Looked up these paths: 
  "/Users/holger/projects/ikusei/opensource/sprockets-test-app/app/assets/images"
  "/Users/holger/projects/ikusei/opensource/sprockets-test-app/app/assets/javascripts"
  "/Users/holger/projects/ikusei/opensource/sprockets-test-app/app/assets/other_javascripts"
  "/Users/holger/projects/ikusei/opensource/sprockets-test-app/app/assets/stylesheets"
  "/Users/holger/projects/ikusei/opensource/sprockets-test-app/lib/assets/javascripts"
  "/Users/holger/projects/ikusei/opensource/sprockets-test-app/vendor/assets/javascripts"
  "/Users/holger/projects/ikusei/opensource/sprockets-test-app/vendor/assets/stylesheets"
  "/Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/turbolinks-2.5.3/lib/assets/javascripts"
  "/Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/jquery-rails-4.1.0/vendor/assets/javascripts"
  "/Users/holger/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/coffee-rails-4.1.1/lib/assets/javascripts"

The problem here is that we accidentally put out SO much information it makes debugging harder.

This got me thinking that maybe we could either add some kind of command that can be used for debugging like rake assets:paths that will output all the paths, we could add to the output.

Make sure that your asset is on the sprockets load path. To see all the paths run rake assets:paths.

Another alternative could be to raise a special Sprockets exception and have the sprockets middleware catch and display a debugging page in development like Rails does with ActionDispatch::DebugExceptions or maybe to extend the functionality of DebugExceptions so that it allows custom pages. Just now realized that it's an ActionView error that gets raised. Kinda thinking aloud right now.

Let's move forwards with the paths in the config on different lines

message << "\nChecked in these paths: \n  #{ config[:paths].join("\n  ") }"

You can test the exception in test_resolve.rb something like this:

  test "adds paths to exceptions" do
    random_path = SecureRandom.hex
    @env.append_path(random_path)

    error = assert_raises(Sprockets::FileNotFound) do
      uri, _ = @env.resolve!("thisfiledoesnotexistandshouldraiseerrors", {})
      uri
    end

    assert_match /#{ random_path }/, error.message
  end

How does that sound?

@5minpause
Copy link
Contributor Author

That does sound like a good idea.
I will update the PR accordingly. Thank you.

In #251 @matthewd mentioned

Enumerating the paths we searched would certainly clarify the behaviour, but might be quite the flood of information: in an average setup, there are a lot of directories on the load path.

One thought: what if we enumerated the logical path to every known asset with a matching basename? (only in debug, of course)

Is that something that you'd find necessary?

@schneems
Copy link
Member

One thought: what if we enumerated the logical path to every known asset with a matching basename? (only in debug, of course)

That's tough, there's not always a basename given. For now let's put more debug info in. We can work on refining it later.

@5minpause
Copy link
Contributor Author

Alright @schneems it looks like this now:
screen shot 2016-06-22 at 09 48 03

Thank you for your input.

@5minpause
Copy link
Contributor Author

What is the problem with AppVeyor?

Specify a project or solution file. The directory does not contain a project or solution file.

I don't understand this message.

@schneems
Copy link
Member

3.x doesn't work on windows it's fine. Merging in. Then going to forward port to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants