jdx/mise · error · RuntimeError

resource # : stage requires a target or a block

Error message

resource #{name}: stage requires a target or a block

What it means

Resource#stage in the brew shim accepts either a target directory (unpack into it) or a block (yield inside the unpacked tree). It raises when neither is supplied, since there is no defined behavior for staging with no destination and no callback.

Solutions

  1. Pass a target Pathname/dir string: `res.stage(target_dir)`.
  2. Or pass a block: `res.stage { |r| install r }`.
  3. If you only need the download, call fetch-style APIs instead of stage.

Example fix

# before
resource("extras").stage
# after
resource("extras").stage("#{buildpath}/extras")
Defensive patterns

Strategy: validation

Validate before calling

raise "stage needs target or block" if target.nil? && !block_given?

Try / catch

begin
  res.stage(target)
rescue RuntimeError => e
  raise unless e.message.include?("stage requires a target")
  res.stage { |r| r.install lib }
end

Prevention

When it happens

Trigger: Calling `resource.stage` with zero arguments and no block, e.g. `res.stage` instead of `res.stage(to_dir)` or `res.stage { |r| ... }`.

Common situations: Porting Homebrew formula code where the real Homebrew Resource#stage defaults differently; refactors that dropped the block but left the call; misreading the shim API as stage-free.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/59919cbdaa24c21a. Report an issue: GitHub.

Appendix: source

Thrown at src/system/packages/brew/shim.rb:429

    # artifact — refuse instead
    shim_unsupported!("resource patches")
  end

  # unpack into `target` (or a tmpdir) and run the optional block there
  def stage(target = nil, &block)
    shim_unsupported!("resource with download strategy #{using.inspect}") unless using.nil?
    raise "resource #{name}: missing url" if @url.nil?
    archive = MiseDownload.fetch(@url, @sha256, "resource #{name}")
    if target
      target = Pathname.new(target.to_s)
      stage_dir = Pathname.new(Dir.mktmpdir("mise-resource-"))
      root = MiseDownload.unpack(archive, stage_dir)
      target.mkpath
      FileUtils.cp_r("#{root}/.", target.to_s)
      FileUtils.remove_entry(stage_dir)
      block&.call(self)
    else
      raise "resource #{name}: stage requires a target or a block" unless block
      Dir.mktmpdir("mise-resource-") do |dir|
        root = MiseDownload.unpack(archive, Pathname.new(dir))
        Dir.chdir(root) { block.call(self) }
      end
    end
  end
end

class PatchSpec
  def initialize(strip, formula_file)
    @strip = strip
    @formula_file = formula_file
  end

  def url(url = nil, **)
    @url = url unless url.nil?
    @url
  end

View on GitHub (pinned to 533346cc37)