puppetlabs/puppet · error · ArgumentError
A block is required
Error message
A block is required
What it means
Puppet::HTTP::ResponseNetHTTP#read_body streams the response body by yielding decoded chunks to a block (it delegates to Net::HTTP's read_body). Calling it without a block cannot stream anything, so it raises ArgumentError; to get the whole body as a String use Response#body instead.
Source
Thrown at lib/puppet/http/response_net_http.rb:24
class Puppet::HTTP::ResponseNetHTTP < Puppet::HTTP::Response
# Create a response associated with the URL.
#
# @param [URI] url
# @param [Net::HTTPResponse] nethttp The response
def initialize(url, nethttp)
super(url, nethttp.code.to_i, nethttp.message)
@nethttp = nethttp
end
# (see Puppet::HTTP::Response#body)
def body
@nethttp.body
end
# (see Puppet::HTTP::Response#read_body)
def read_body(&block)
raise ArgumentError, "A block is required" unless block_given?
@nethttp.read_body(&block)
end
# (see Puppet::HTTP::Response#success?)
def success?
@nethttp.is_a?(Net::HTTPSuccess)
end
# (see Puppet::HTTP::Response#[])
def [](name)
@nethttp[name]
end
# (see Puppet::HTTP::Response#each_header)
def each_header(&block)
@nethttp.each_header(&block)
endView on GitHub (pinned to e227c27540)
Solutions
- Pass a block: response.read_body { |chunk| out.write(chunk) }.
- If you want the full body, call response.body instead.
- When forwarding, guard with block_given? before calling read_body.
Example fix
# before
body = response.read_body
# after (streaming)
response.read_body { |chunk| socket.write(chunk) }
# after (full body)
body = response.body Defensive patterns
Strategy: validation
Validate before calling
if block response.read_body(&block) else response.body end
Type guard
has_block = ->(&b) { !b.nil? }
raise ArgumentError, 'pass a block or use #body' unless has_block { |&blk| blk } Prevention
- Use response.body for the full string; read_body is streaming-only.
- When forwarding optional blocks, check block_given? before delegating.
When it happens
Trigger: response.read_body with no block (e.g. assigning its result: body = response.read_body); forwarding &block when block is nil; code ported from Net::HTTP where read_body without a block returns the full body string.
Common situations: Developers used to net/http semantics calling read_body expecting a String return; partial refactors where the consumer callback was removed but the call kept; block passed as &nil via an optional kwarg default.
Related errors
- 'put' requires a string 'body' argument
- 'post' requires a string 'body' argument
- No content type in http response; cannot parse
- Could not download module: %{message}
- No format matches the given format name or mime-type (%{form
AI-assisted analysis of puppetlabs/puppet@e227c27540 (2026-08-21).
Data as JSON: /api/errors/3e43ccefceebc604.
Report an issue: GitHub.