{"record":{"id":"59919cbdaa24c21a","repo":"jdx/mise","slug":"resource-name-stage-requires-a-target-or-a-blo","errorCode":null,"errorMessage":"resource #{name}: stage requires a target or a block","messagePattern":"resource #(.+?): stage requires a target or a block","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/shim.rb","lineNumber":429,"sourceCode":"    # artifact — refuse instead\n    shim_unsupported!(\"resource patches\")\n  end\n\n  # unpack into `target` (or a tmpdir) and run the optional block there\n  def stage(target = nil, &block)\n    shim_unsupported!(\"resource with download strategy #{using.inspect}\") unless using.nil?\n    raise \"resource #{name}: missing url\" if @url.nil?\n    archive = MiseDownload.fetch(@url, @sha256, \"resource #{name}\")\n    if target\n      target = Pathname.new(target.to_s)\n      stage_dir = Pathname.new(Dir.mktmpdir(\"mise-resource-\"))\n      root = MiseDownload.unpack(archive, stage_dir)\n      target.mkpath\n      FileUtils.cp_r(\"#{root}/.\", target.to_s)\n      FileUtils.remove_entry(stage_dir)\n      block&.call(self)\n    else\n      raise \"resource #{name}: stage requires a target or a block\" unless block\n      Dir.mktmpdir(\"mise-resource-\") do |dir|\n        root = MiseDownload.unpack(archive, Pathname.new(dir))\n        Dir.chdir(root) { block.call(self) }\n      end\n    end\n  end\nend\n\nclass PatchSpec\n  def initialize(strip, formula_file)\n    @strip = strip\n    @formula_file = formula_file\n  end\n\n  def url(url = nil, **)\n    @url = url unless url.nil?\n    @url\n  end","sourceCodeStart":411,"sourceCodeEnd":447,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/brew/shim.rb#L411-L447","documentation":"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.","triggerScenarios":"Calling `resource.stage` with zero arguments and no block, e.g. `res.stage` instead of `res.stage(to_dir)` or `res.stage { |r| ... }`.","commonSituations":"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.","solutions":["Pass a target Pathname/dir string: `res.stage(target_dir)`.","Or pass a block: `res.stage { |r| install r }`.","If you only need the download, call fetch-style APIs instead of stage."],"exampleFix":"# before\nresource(\"extras\").stage\n# after\nresource(\"extras\").stage(\"#{buildpath}/extras\")","handlingStrategy":"validation","validationCode":"raise \"stage needs target or block\" if target.nil? && !block_given?","typeGuard":null,"tryCatchPattern":"begin\n  res.stage(target)\nrescue RuntimeError => e\n  raise unless e.message.include?(\"stage requires a target\")\n  res.stage { |r| r.install lib }\nend","preventionTips":["Remember the shim's stage requires target-or-block (no default)","Wrap resource staging in a helper that enforces a target","Review refactors that touched stage call sites"],"tags":["ruby","brew-shim","resource","api-usage"],"backgroundTag":"missing-required-argument","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}