{"record":{"id":"82d551ff121b6d13","repo":"jdx/mise","slug":"patch-failed-output","errorCode":null,"errorMessage":"patch failed:\n#{output}","messagePattern":"patch failed:\n#(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/shim.rb","lineNumber":477,"sourceCode":"    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\n  end\nend\n\n# reference to an installed dependency, as returned by Formula[\"name\"]\nclass DependencyFormula\n  def initialize(name) = @name = name\n\n  def opt_prefix = MISE_BREW_PREFIX + \"opt\" + @name\n  def opt_bin = opt_prefix + \"bin\"\n  def opt_lib = opt_prefix + \"lib\"\n  def opt_include = opt_prefix + \"include\"\n  def opt_libexec = opt_prefix + \"libexec\"\n  def opt_share = opt_prefix + \"share\"\n  def opt_frameworks = opt_prefix + \"Frameworks\"\n\n  # resolved keg path (through the opt symlink)","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/brew/shim.rb#L459-L495","documentation":"Patch#apply_content pipes patch text into the external `patch` tool (`patch -g 0 -f -p<strip>`) and raises with the tool's output when it exits non-zero. This means the unified diff did not apply cleanly to the source tree.","triggerScenarios":"The patch's context lines no longer match the source (upstream code changed); the wrong -p strip level for the diff's paths; the file the patch touches doesn't exist; line-ending or whitespace differences (CRLF vs LF).","commonSituations":"Formula updated to a new upstream version where an old patch no longer applies; patches generated with different path prefixes; Windows checkouts altering line endings before patching.","solutions":["Read the printed `patch failed:` output to find the failing hunk and file.","Regenerate the patch against the current source version.","Adjust the formula's patch strip level (`:p1` etc.) to match the diff's path prefixes.","Drop the patch if upstream already applied the change in the new version."],"exampleFix":"# before\npatch do\n  url \"https://example.com/fix-for-1.2.patch\"\nend\n# after\n# regenerate fix-for-1.3.patch against the new sources\npatch :p0 do\n  url \"https://example.com/fix-for-1.3.patch\"\nend","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"begin\n  patch.apply!\nrescue RuntimeError => e\n  raise unless e.message.start_with?(\"patch failed:\")\n  warn e.message  # includes patch tool output; regenerate or adjust strip\nend","preventionTips":["Regenerate patches on every upstream version bump","Match the -p strip level to the diff's path prefixes","Normalize line endings before applying patches","Drop patches upstream has already incorporated"],"tags":["ruby","brew-shim","patch","subprocess"],"backgroundTag":"command-failed","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"}