jdx/mise · error · RuntimeError
inreplace: #{before.inspect} not found
Error message
inreplace: #{before.inspect} not found What it means
This error comes from a small inreplace helper (a port of Homebrew's `inreplace` utility) that wraps `String#gsub!`. When `gsub!` finds no match it returns nil, and unless auditing is disabled (`audit_result = false`), the helper raises 'inreplace: <pattern> not found' to signal that the expected text was not present in the file/string being edited. It exists so silent no-op replacements are caught instead of corrupting files unnoticed.
Source
Thrown at src/system/packages/brew/shim.rb:877
def time = Time.now
def post_install; end
# unknown instance helpers: fail loudly
def method_missing(name, *args, &block)
shim_unsupported!("#{name} (install-time helper)")
end
def respond_to_missing?(_name, _include_private = false) = true
class InreplaceText
attr_reader :text
def initialize(text) = @text = text
def gsub!(before, after, audit_result = true)
result = @text.gsub!(before, after.to_s)
raise "inreplace: #{before.inspect} not found" if result.nil? && audit_result
result
end
def sub!(before, after)
@text.sub!(before, after.to_s)
end
def change_make_var!(flag, new_value)
replaced = @text.gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?\\+\\:]?=[ \t]*((?:.*\\\n)*.*)$/, "#{flag}=#{new_value}")
opoo "change_make_var! #{flag} did nothing" if replaced.nil?
replaced
end
end
end
def main
load MISE_BREW_FORMULA_FILE.to_s
klass = Formula.instance_variable_get(:@formula_subclass)View on GitHub (pinned to afd2eddd3a)
Solutions
- Print/inspect the actual file content and update the `before` pattern so it matches current text
- Confirm the pattern is being applied to the right file/version (pin or update the tool version the pattern was written for)
- Make the regex more permissive (e.g. allow optional whitespace or alternative spellings)
- If the replacement is genuinely optional, pass `audit_result = false` so a missing match does not raise
- Report/update the shim pattern for the new upstream version
Example fix
# before
s.gsub!('prefix=/usr/local', "prefix=#{HOMEBREW_PREFIX}")
# after
raise "unexpected Makefile layout" unless s.text.include?('prefix=')
s.gsub!(/^prefix\s*=.*$/, "prefix=#{HOMEBREW_PREFIX}") Defensive patterns
Strategy: validation
Validate before calling
raise 'pattern missing from file' unless text.include?(pattern) # check before calling gsub! text.gsub!(pattern, replacement)
Try / catch
begin
s.gsub!(pattern, replacement)
rescue RuntimeError => e
raise e unless e.message.start_with?('inreplace:')
# handle no-op replacement: log and continue or fall back
end Prevention
- Verify patterns against the exact file/version before patching
- Prefer anchored, permissive regexes over brittle literal strings
- Use audit_result: false only when the replacement is truly optional
- Add a test that runs the replacement against the current upstream file
When it happens
Trigger: Calling `gsub!(before, after)` on the helper with a `before` pattern that does not match any substring of `@text`; the pattern may be a literal string, regex, or a dynamic pattern built from a version string that changed upstream.
Common situations: Patching formulas/casks during brew-based installs where upstream source changed a line (version bump renamed a flag, path, or shebang); regex built from an interpolated version that no longer appears; running against a newer upstream release before the shim pattern is updated.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- no precompiled ruby is available for this platform To compil
- Ruby engine '{}' is not supported on Windows. Only standard
- no precompiled ruby is available for this platform\nTo compi
- no precompiled ruby found for {tv} on {platform}
- no precompiled ruby is available for this platform
AI-assisted analysis of jdx/mise@afd2eddd3a (2026-09-09).
Data as JSON: /api/errors/ba6843212c44667e.
Report an issue: GitHub.