Closed alekgosk closed 1 month ago
I would start by writing a spec in Grape 1.6 to reproduce this and bisect to a change between 1.6 and 1.8.
There has also been quite a few rack-related changes since 1.8. We can see if that test passes now and commit the test to ensure it doesn't break in the future.
@alekgosk headers is {}
unless you pass nil
.
https://github.com/ruby-grape/grape/blob/a6cde5d5fb00ea7cf34f7adfbe81dcd2b3958e8d/lib/grape/middleware/error.rb#L53 Any chance that you call error!
where the 3rd parameter is nil
?
Good catch @ericproulx, the culrpit is currently the following code:
# this code comes from a trait
rescue_from :grape_exceptions do |e|
# e.headers is nil here when request body is malformed
error! e.message, e.status, e.headers
end
rescue_from :grape_exceptions
and It's been released in 1.8.0. So in 1.6.2, your block has never been executed. I would suggest to just remove the block and let grape handle it for you. FYI, It will works from 2.1.0Thanks for digging this up @ericproulx! @alekgosk close?
Yup, I think we can close it, thanks @dblock
Environment
Description
After upgrading Grape from version 1.6.2 to 1.8.0, we started encountering a
NoMethodError
fornil:NilClass
when callingreverse_merge
on theheaders
variable. This issue occurs in our custom middleware where we manipulate the headers.Steps to Reproduce
reverse_merge
on theheaders
variable.Expected Behavior
The
headers
variable should be able to merge with another hash without throwing an error, as it worked in Grape version 1.6.2.Actual Behavior
The application throws a
NoMethodError
indicating thatreverse_merge
is called onnil:NilClass
. This suggests that theheaders
variable isnil
at the time of the call.Error Log
Rspec test that is failing