Commit Graph

56 Commits

Author SHA1 Message Date
Yuki Nishijima
6922ba6cb6 Prefer strings over regex expressions
In this case statement, there are two patterns that start with the same
line:

  when %r{/not_found}
    ...
  when %r{/not_found_original_exception}
    ...

Because the string "/not_found_original_exception" does match the first
one, it is never routed to what it is supposed to be routed, causing one
of the tests for DebugExceptions to happen to be passing.

After changing the regex expressions back to strings, I noticed that the
test setup is not complete (the template object needs to be a proper
template object). Once I fixed it all the tests started padding.
2019-01-24 15:49:05 -05:00
alkesh26
78cf58b765 1. Replaced unused variables by _.
2. Typo fixes.
2019-01-22 22:27:01 +05:30
Ryuta Kamizono
892e38c78e Enable Style/RedundantBegin cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).

I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
2018-12-21 06:12:42 +09:00
yuuji.yaginuma
1b86d90136 Enable Performance/UnfreezeString cop
In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`.

```ruby
# frozen_string_literal: true

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "benchmark-ips"
end

Benchmark.ips do |x|
  x.report('+@') { +"" }
  x.report('dup') { "".dup }
  x.compare!
end
```

```
$ ruby -v benchmark.rb
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
Warming up --------------------------------------
                  +@   282.289k i/100ms
                 dup   187.638k i/100ms
Calculating -------------------------------------
                  +@      6.775M (± 3.6%) i/s -     33.875M in   5.006253s
                 dup      3.320M (± 2.2%) i/s -     16.700M in   5.032125s

Comparison:
                  +@:  6775299.3 i/s
                 dup:  3320400.7 i/s - 2.04x  slower

```
2018-09-23 08:56:55 +09:00
Yuki Nishijima
1f525b4f7d Show nested exceptions on the debug view 2018-07-15 20:54:19 -04:00
Genadi Samokovarov
d25fba89d4 Introduce ActionDispatch::DebugExceptions interceptors
Plugins interacting with the exceptions caught and displayed by
ActionDispatch::DebugExceptions currently have to monkey patch it to get
the much needed exception for their calculation.

With DebugExceptions.register_interceptor, plugin authors can hook into
DebugExceptions and process the exception, before being rendered. They
can store it into the request and process it on the way back of the
middleware chain execution or act on it straight in the interceptor.

The interceptors can be play blocks, procs, lambdas or any object that
responds to `#call`.
2018-04-20 14:55:37 +03:00
Koichi ITO
d2901bd517 [Action Pack] rubocop -a --only Layout/EmptyLineAfterMagicComment 2017-07-11 13:12:32 +09:00
Kir Shatrov
b3f3d49fd6 Prepare AP and AR to be frozen string friendly 2017-07-06 21:30:43 +03:00
Matthew Draper
87b3e226d6 Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"
This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing
changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
2017-07-02 02:15:17 +09:30
Kir Shatrov
cfade1ec7e Enforce frozen string in Rubocop 2017-07-01 02:11:03 +03:00
Rafael Mendonça França
fe1f4b2ad5
Add more rubocop rules about whitespaces 2016-10-29 01:17:49 -02:00
Genadi Samokovarov
f99c37583d Support plain loggers in DebugExceptions
I have been seeing people setting `Logger` instances for `config.logger`
and it blowing up on `rails/web-console` usage.

Now, I doubt many folks are manually setting `ActionView::Base.logger`,
but given that `DebugExceptions` is running in a pretty fragile
environment already, having it crash (and being silent) in those cases
can be pretty tricky to trace down.

I'm proposing we verify whether the `ActionView::Base.logger` supports
silencing before we try to do it, to save us the headache of tracing it
down.
2016-10-28 23:53:06 +03:00
Rafael Mendonça França
55f9b8129a
Add three new rubocop rules
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces

Fix all violations in the repository.
2016-08-16 04:30:11 -03:00
Xavier Noria
b326e82dc0 applies remaining conventions across the project 2016-08-06 20:20:22 +02:00
Xavier Noria
35b3de8021 applies new string literal convention in actionpack/test
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
2016-08-06 18:54:50 +02:00
Matthew Draper
1c7a3230ba Ensure logging on exceptions only includes what we expect 2016-07-02 06:09:10 +09:30
Santiago Pastorino
5f7d3363c5 Merge pull request #24912 from prathamesh-sonpatki/api-fix-response-format
API only apps: Preserve request format for HTML requests too
2016-05-11 11:13:35 -03:00
Prathamesh Sonpatki
c33bda875e
API only apps: Preserve request format for HTML requests too
- Earlier we were responding with JSON format for HTML requests in a API
  app.
- Now we will respond with HTML format for such requests in API apps.
- Also earlier we were not testing the API app's JSON requests
  properly. We were actually sending HTML requests. Now we send correct
  JSON requests. Also added more test coverage.
- Based on the discussion from this commit -
  05d89410bf.

[Prathamesh Sonpatki, Jorge Bejar]
2016-05-11 09:04:02 +05:30
Prathamesh Sonpatki
6e189a2e3b
BoomerAPI is not used anywhere, so removed it!
- It was originally added in 83b4e9073f0852afc065 and partially
  removed in 05d89410bf97d0778e7.
2016-05-06 14:33:31 -05:00
Jorge Bejar
6fa2023c81 DebugException initialize with a response_format value 2015-12-09 10:53:45 -03:00
Jorge Bejar
05d89410bf Fix some edge cases in AD::DebugExceptions in rails api apps 2015-12-09 10:53:44 -03:00
Jorge Bejar
83b4e9073f Response when error should be formatted properly in Rails API if local request 2015-12-09 10:53:41 -03:00
Rafael França
40acdcfb7c Merge pull request #22172 from tijmenb/fix-source-in-show-exception
Add text template for source code
2015-11-24 02:11:09 -02:00
Jake Worth
432c7a5b76 Fix typo [ci skip] 2015-11-12 10:06:44 -06:00
Tijmen Brommet
08689a2d1f Add text template for source code
When a request is made with AJAX and an error occurs, Rails will render
a text-template for the exception instead of the HTML error page
(#11960).

The `.text.erb` variant of the `_source` template is currently missing,
causing HTML to be rendered in the response. This commit adds the text
template.

To keep the page scannable we only only show the first three source
extracts.

Related to #14745.

Before:

```
~/testing-exceptions  ᐅ curl 'http://localhost:3000/' -H
'X-Requested-With: XMLHttpRequest'
RuntimeError in PostsController#index

    <div class="source " id="frame-source-0">
      <div class="info">
        Extracted source (around line <strong>#3</strong>):
      </div>
      <div class="data">
        <table cellpadding="0" cellspacing="0" class="lines">
          <tr>
```

After:

```
~/testing-exceptions  ᐅ curl 'http://localhost:3000/' -H
'X-Requested-With: XMLHttpRequest'
RuntimeError in PostsController#index

Extracted source (around line #3):

*3     raise
```
2015-11-03 22:13:10 +00:00
Yuki Nishijima
266455cf25 Deprecate exception#original_exception in favor of exception#cause 2015-11-03 06:54:34 -08:00
Marcin Olichwirowicz
81bc771e7c Remove mocha from ActionPack tests 2015-09-05 16:58:40 +02:00
Marcin Olichwirowicz
00234f5619 Get rid of mocha tests - part 2 2015-08-25 09:28:06 +02:00
Robin Dupret
586fe4471d Avoid accurate assertions on error messages
Since there are disparities between the raised error messages on the
different implementations, let's avoid being too accurate.
2015-03-02 14:05:07 +01:00
Rafael Mendonça França
bb6fe7e73a Consistent usage of spaces in hashes across our codebase 2015-01-29 12:19:41 -02:00
Kir Shatrov
baf14ae513 Switch to kwargs in ActionController::TestCase and ActionDispatch::Integration
Non-kwargs requests are deprecated now.
Guides are updated as well.

`post url, nil, nil, { a: 'b' }` doesn't make sense.
`post url, params: { y: x }, session: { a: 'b' }` would be an explicit way to do the same
2015-01-29 14:44:46 +02:00
Kir Shatrov
083f657c0f Refactor debug view
Avoid logic in ERB and use helpers
2014-12-02 09:45:20 -05:00
Genadi Samokovarov
92ace39692 Show source view and backtrace on missing template errors
This will help you debug missing template errors, especially if they
come from a programmatic template selection. Thanks to @dhh for
suggesting that.

As a bonus, also show request and response info on the routing error
page for consistency.
2014-11-24 22:06:11 +02:00
Byron Bischoff
dbcbbcf2bc Show the user’s application in the source window and select the correct trace list, closes #17312 2014-10-23 09:53:43 -07:00
Akira Matsuda
b30b99c615 Expectations first 2014-08-18 15:40:53 +09:00
Yves Senn
171818c60c Merge pull request #16303 from rajcybage/removing_master
remove empty unused method
2014-07-28 17:22:53 +02:00
Rajarshi Das
f6a52f1e9d add comment to the empty each method for not removing it in future 2014-07-26 20:05:31 +05:30
Vlad Bokov
59dbf68960 Display diagnostics in text format for xhr request 2014-04-14 20:48:13 +07:00
Boris Kuznetsov
6af07c27ae Append link to bad code to backtrace when exception is SyntaxError 2014-03-27 00:36:59 +04:00
Guillermo Iguaran
f886fe2d8c Revert "Merge pull request #9660 from sebasoga/change_strong_parameters_require_behaviour"
This reverts commit c2b5a8e61ba0f35015e6ac949a5c8fce2042a1f2, reversing
changes made to 1918b12c0429caec2a6134ac5e5b42ade103fe90.

See: https://github.com/rails/rails/pull/9660#issuecomment-27627493
2013-11-02 14:30:03 -05:00
Guillermo Iguaran
c2b5a8e61b Merge pull request #9660 from sebasoga/change_strong_parameters_require_behaviour
Change ActionController::Parameters#require behavior when value is empty
2013-11-01 17:28:05 -07:00
Kir Shatrov
a725a453b3 Display exceptions in text format for xhr request 2013-08-22 22:20:34 +04:00
Lewis Marshall
ec462b4de7 Return a 405 response for unknown HTTP methods 2013-04-22 14:31:10 +01:00
Sebastian Sogamoso
b3f894c528 Change ActionController::Parameters#require behavior when value is empty
When the value for the required key is empty an ActionController::ParameterMissing is raised which gets caught by ActionController::Base and turned into a 400 Bad Request reply with a message in the body saying the key is missing, which is misleading.

With these changes, ActionController::EmptyParameter will be raised which ActionController::Base will catch and turn into a 400 Bad Request reply with a message in the body saying the key value is empty.
2013-03-11 09:28:22 -05:00
Brian Alexander
8e221127ab strong parameters exception handling 2013-01-15 17:45:34 -07:00
Yves Senn
80795e02ca display mountable engine routes on RoutingError. 2013-01-05 14:31:03 +01:00
Guillermo Iguaran
a27c4f6095 Fix test for DebugExceptions due to template change 2012-12-31 16:48:10 -05:00
schneems
0b6175ac2d Add Missing Keys from Journey on failed URL format
Many named routes have keys that are required to successfully resolve. If a key is left off like this:

    <%= link_to 'user', user_path %>

This will produce an error like this:

    No route matches {:action=>"show", :controller=>"users"}

Since we know that the :id is missing, we can add extra debugging information to the error message.

    No route matches {:action=>"show", :controller=>"users"} missing required keys: [:id]


This will help new and seasoned developers look closer at their parameters. I've also subclassed the routing error to be clear that this error is a result of attempting to generate a url and not because the user is trying to visit a bad url. 

While this may sound trivial this error message is misleading and confuses most developers. The important part isn't what's in the options its's what's missing. Adding this information to the error message will make debugging much more obvious. 

This is the sister pull request of https://github.com/rails/journey/pull/44 which will be required to get they missing keys into the correct error message. 

Example Development Error in Rails: http://cl.ly/image/3S0T0n1T3421
2012-08-28 08:53:45 -07:00
Andrew White
66eb3f02cc Raise ActionController::BadRequest for malformed parameter hashes.
Currently Rack raises a TypeError when it encounters a malformed or
ambiguous hash like `foo[]=bar&foo[4]=bar`. Rather than pass this
through to the application this commit captures the exception and
re-raises it using a new ActionController::BadRequest exception.

The new ActionController::BadRequest exception returns a 400 error
instead of the 500 error that would've been returned by the original
TypeError. This allows exception notification libraries to ignore
these errors if so desired.

Closes #3051
2012-05-20 19:07:04 +01:00
brainopia
73709f7ffa Removed unused assigns from ActionView::Template::Error
They existed since initial rails commit by DHH but lost use a long time
ago
2012-01-20 20:13:29 +04:00