{"record":{"id":"eaa12c6b8385a1ad","repo":"jdx/mise","slug":"formula-declares-a-data-patch-but-has-no-end-s","errorCode":null,"errorMessage":"formula declares a DATA patch but has no __END__ section","messagePattern":"formula declares a DATA patch but has no __END__ section","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/shim.rb","lineNumber":461,"sourceCode":"\n  def url(url = nil, **)\n    @url = url unless url.nil?\n    @url\n  end\n\n  def sha256(sha = nil)\n    @sha256 = sha unless sha.nil?\n    @sha256\n  end\n\n  def data!\n    @data = true\n  end\n\n  def apply!\n    if @data\n      content = @formula_file.read.split(/^__END__$/, 2)[1]\n      raise \"formula declares a DATA patch but has no __END__ section\" if content.nil?\n      apply_content(content.sub(/\\A\\n/, \"\"))\n    elsif @url\n      file = MiseDownload.fetch(@url, @sha256, \"patch\")\n      apply_content(file.read)\n    end\n  end\n\n  private\n\n  def apply_content(content)\n    ohai \"Applying patch (-p#{@strip})\"\n    Open3.popen2e(\"patch\", \"-g\", \"0\", \"-f\", \"-p#{@strip}\") do |stdin, out, thread|\n      stdin.write(content)\n      stdin.close\n      output = out.read\n      raise \"patch failed:\\n#{output}\" unless thread.value.success?\n      $stdout.puts output\n    end","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/brew/shim.rb#L443-L479","documentation":"The brew shim's Patch#apply! supports DATA-style patches whose content lives after `__END__` in the formula file. It raises when a patch was declared with `:DATA` (setting @data = true) but the formula file contains no `__END__` marker, so split returns nil content.","triggerScenarios":"A formula adds `patch :DATA` without appending a `__END__` section holding the unified diff; the `__END__` line was removed or misspelled (e.g. whitespace/casing preventing the /^__END__$/ match).","commonSituations":"Hand-edited formulas where the diff was deleted but the `patch :DATA` declaration remained; ported formulas from Homebrew where the data section was stripped by tooling.","solutions":["Append a `__END__` line followed by the patch content to the formula file.","Remove the `patch :DATA` declaration if the patch is no longer needed.","Convert to a URL-based patch (`patch do url ... end`) instead of DATA.","Check for invisible characters/casing that break the /^__END__$/ match."],"exampleFix":"# before\npatch :DATA\n# (file ends without __END__)\n# after\npatch :DATA\n__END__\n--- a/src/config.c\n+++ b/src/config.c\n@@ -1,3 +1,3 @@\n...","handlingStrategy":"validation","validationCode":"text = formula_file.read\nraise \"DATA patch needs __END__\" if text[/^__END__$/].nil? && text.match?(/^\\s*patch\\s+:DATA/)","typeGuard":null,"tryCatchPattern":"begin\n  patch.apply!\nrescue RuntimeError => e\n  raise unless e.message.include?(\"__END__ section\")\n  # add __END__ data or drop the patch\nend","preventionTips":["When adding `patch :DATA`, immediately append __END__ + diff","Grep formulas for `patch :DATA` and verify each has __END__","Prefer URL patches over DATA for tooling-friendliness"],"tags":["ruby","brew-shim","patch","formula"],"backgroundTag":"internal-invariant-violation","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"}