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

Puma caught this error: undefined method `body' for Rack::Files::Iterator #21

Open
raihanM99 opened this issue Mar 8, 2024 · 2 comments

Comments

@raihanM99
Copy link

In my Rails project, I encountered an issue related to handling attachments. Specifically, when accessing a page that invokes an attachment from Active Storage using (e.g <%= user.avatar %>), an error occurred.

Puma caught this error: undefined method `body' for #<Rack::Files::Iterator:0x00007a6444b5d0b0 @path="/app/storage/up/0j/up0jdccu1cxhetiqc4esuczuufde", @ranges=[0..13031], @options={:mime_type=>"text/plain", :size=>13032}>

      @stream.body
             ^^^^^ (NoMethodError)
/gems/ruby/3.1.0/gems/actionpack-7.0.4/lib/action_dispatch/http/response.rb:305:in `body'
/gems/ruby/3.1.0/gems/debugbar-0.2.2/lib/debugbar/request.rb:94:in `response_hash'
/gems/ruby/3.1.0/gems/debugbar-0.2.2/lib/debugbar/request.rb:60:in `to_h'
.
.
.

This issue arose due to Rails generating a URL every time it accesses the Active Storage attachment.

"GET /uploads/disk/active_storage_long_key/avatar1.jpg"

To resolve this, I modified the configuration in the config/initializers/debugbar.rb file to ignore /uploads, which successfully resolved the issue

Debugbar.configure do |config|
  config.ignore_request = -> (env) { env['PATH_INFO'].start_with? '/uploads' }
end
@bitsmyth
Copy link

bitsmyth commented Oct 4, 2024

@raihanM99 thank you!

I also checked if it is defined as test and production do not load debugbar and therefor will break the initialization.

if defined? Debugbar
  Debugbar.configure do |config|
    config.ignore_request = ->(env) { env["PATH_INFO"].start_with? "/uploads" }
  end
end

@gtrias
Copy link

gtrias commented Dec 2, 2024

Hello! I'm having the same problem but this workaround doesn't fit very well into our system since we get this errors from a GraphQL endpoint on which you would need to introspect the query to know if it's dealing with files.

It's also a pity not being able to see requests involving files in debugbar.
Would it be possible to use another mechanism to generate response_hash here? https://github.com/julienbourdeau/debugbar/blob/master/lib/debugbar/request.rb#L94 Why it needs to use response.body for it?

I would be happy to contribute if you guide me on how to do so :)

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

No branches or pull requests

3 participants