jdx/mise · error · RuntimeError
patch failed: #
Error message
patch failed:
#{output} What it means
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.
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.
Example fix
# before patch do url "https://example.com/fix-for-1.2.patch" end # after # regenerate fix-for-1.3.patch against the new sources patch :p0 do url "https://example.com/fix-for-1.3.patch" end
Defensive patterns
Strategy: try-catch
Try / catch
begin
patch.apply!
rescue RuntimeError => e
raise unless e.message.start_with?("patch failed:")
warn e.message # includes patch tool output; regenerate or adjust strip
end Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- command failed: #
- completion generation failed: #
- formula declares a DATA patch but has no __END__ section
- patch failed:\n#
- cannot install # : does not exist
AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17).
Data as JSON: /api/errors/82d551ff121b6d13.
Report an issue: GitHub.
Appendix: source
Thrown at src/system/packages/brew/shim.rb:477
if @data
content = @formula_file.read.split(/^__END__$/, 2)[1]
raise "formula declares a DATA patch but has no __END__ section" if content.nil?
apply_content(content.sub(/\A\n/, ""))
elsif @url
file = MiseDownload.fetch(@url, @sha256, "patch")
apply_content(file.read)
end
end
private
def apply_content(content)
ohai "Applying patch (-p#{@strip})"
Open3.popen2e("patch", "-g", "0", "-f", "-p#{@strip}") do |stdin, out, thread|
stdin.write(content)
stdin.close
output = out.read
raise "patch failed:\n#{output}" unless thread.value.success?
$stdout.puts output
end
end
end
# reference to an installed dependency, as returned by Formula["name"]
class DependencyFormula
def initialize(name) = @name = name
def opt_prefix = MISE_BREW_PREFIX + "opt" + @name
def opt_bin = opt_prefix + "bin"
def opt_lib = opt_prefix + "lib"
def opt_include = opt_prefix + "include"
def opt_libexec = opt_prefix + "libexec"
def opt_share = opt_prefix + "share"
def opt_frameworks = opt_prefix + "Frameworks"
# resolved keg path (through the opt symlink)View on GitHub (pinned to 533346cc37)