ruby / webrick

HTTP server toolkit
BSD 2-Clause "Simplified" License
286 stars 97 forks source link

TypeError: no implicit conversion of Array into String #117

Closed forthrin closed 1 year ago

forthrin commented 1 year ago

Why is this happening, and what is the proper fix?

get '/' do
  content_type 'text/plain'
  request.env.each do |k, v|
    puts "#{k}: #{v}"
  end
end
TypeError: no implicit conversion of Array into String in ./rack-2.2.7/lib/rack/handler/webrick.rb:120
              part = "#{part.join(': ')}\n" if part.is_a?(Array) # Hack
              res.body << part

Notices:

  1. An old version of rack is used (2.2.7 as opposed to the current 3.0.8)
  2. Some users seem to be switching to Puma. Is WEBrick outdated?
ioquatix commented 1 year ago

Do you need to return a response or something?

forthrin commented 1 year ago

No, I just did this to check the environment. (Not to be used in production). Am doing something you're not supposed to do in this context? See also original question: Why is this happening, and what is the proper fix?

ioquatix commented 1 year ago

What framework is

get '/' do
  content_type 'text/plain'
  request.env.each do |k, v|
    puts "#{k}: #{v}"
  end
end
jeremyevans commented 1 year ago

Looks like Sinatra. The issue is the get block is not returning one of Sinatra's expected return values. See the Return Values section of https://sinatrarb.com/intro.html . This appears to be a bug in the app, not in Webrick.

forthrin commented 1 year ago

Yes, Sinatra. Aha, so it's not the code itself, but what is returns that causes problems down the line. I didn't know there was a return value. Not an issue then, or there could possibly be a warning/exception for this. Up to the devs.