-
Notifications
You must be signed in to change notification settings - Fork 207
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
BUGFIX: Fix bug where 'inspect_with_backtrace' raises an IndexError i… #625
Changes from 11 commits
6e1d7ef
6e3240a
97c6439
0250a5d
e63610c
3fd3848
15ad9b4
843fb47
ce6719f
1d6cb4a
0cbe400
394f9f6
c725862
bdafef6
fe085e7
d8e64a6
17131e8
3246f03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,13 +12,7 @@ module Amber::Controller | |
end | ||
|
||
def internal_server_error | ||
response_format("ERROR: #{@ex.inspect_with_backtrace}") | ||
# IMPORTANT: #inspect_with_backtrace will fail in some situtions which breaks the tests. | ||
# Even if you call @ex.callstack you'll notice that backtrace is nil. | ||
# #backtrace? is supposed to be safe but it exceptions anyway. | ||
# Please don't remove this without verifying that crystal core has been fixed first. | ||
rescue ex : IndexError | ||
response_format("ERROR: #{@ex.message}") | ||
response_format("ERROR: #{internal_server_error_message}") | ||
end | ||
|
||
def forbidden | ||
|
@@ -33,6 +27,21 @@ module Amber::Controller | |
end | ||
end | ||
|
||
private def internal_server_error_message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with moving this into a private method especially since this only gets called if there's an error. Personally I think we abstract code into methods too much though. In a lot of cases it's just as readable either way and slows down the code minutely every branch we add to the AST. |
||
# IMPORTANT: #inspect_with_backtrace will fail in some situtions which breaks the tests. | ||
# Even if you call @ex.callstack you'll notice that backtrace is nil. | ||
# #backtrace? is supposed to be safe but it exceptions anyway. | ||
# Please don't remove this without verifying that crystal core has been fixed first. | ||
@ex.inspect_with_backtrace | ||
rescue ex : IndexError | ||
@ex.message | ||
rescue ex | ||
<<-ERROR | ||
Original Error: #{@ex.message} | ||
Error during 'inspect_with_backtrace': #{ex.message} | ||
ERROR | ||
end | ||
|
||
private def response_format(message) | ||
case content_type | ||
when "application/json" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should leave these comments here or else someone will refactor it again because they won't understand why there's added complexity here.