{"record":{"id":"ba6843212c44667e","repo":"jdx/mise","slug":"inreplace-before-inspect-not-found","errorCode":null,"errorMessage":"inreplace: #{before.inspect} not found","messagePattern":"inreplace: #(.+?) not found","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/system/packages/brew/shim.rb","lineNumber":877,"sourceCode":"  def time = Time.now\n\n  def post_install; end\n\n  # unknown instance helpers: fail loudly\n  def method_missing(name, *args, &block)\n    shim_unsupported!(\"#{name} (install-time helper)\")\n  end\n\n  def respond_to_missing?(_name, _include_private = false) = true\n\n  class InreplaceText\n    attr_reader :text\n\n    def initialize(text) = @text = text\n\n    def gsub!(before, after, audit_result = true)\n      result = @text.gsub!(before, after.to_s)\n      raise \"inreplace: #{before.inspect} not found\" if result.nil? && audit_result\n      result\n    end\n\n    def sub!(before, after)\n      @text.sub!(before, after.to_s)\n    end\n\n    def change_make_var!(flag, new_value)\n      replaced = @text.gsub!(/^#{Regexp.escape(flag)}[ \\t]*[\\\\?\\\\+\\\\:]?=[ \\t]*((?:.*\\\\\\n)*.*)$/, \"#{flag}=#{new_value}\")\n      opoo \"change_make_var! #{flag} did nothing\" if replaced.nil?\n      replaced\n    end\n  end\nend\n\ndef main\n  load MISE_BREW_FORMULA_FILE.to_s\n  klass = Formula.instance_variable_get(:@formula_subclass)","sourceCodeStart":859,"sourceCodeEnd":895,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/packages/brew/shim.rb#L859-L895","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\ns.gsub!('prefix=/usr/local', \"prefix=#{HOMEBREW_PREFIX}\")\n# after\nraise \"unexpected Makefile layout\" unless s.text.include?('prefix=')\ns.gsub!(/^prefix\\s*=.*$/, \"prefix=#{HOMEBREW_PREFIX}\")","handlingStrategy":"validation","validationCode":"raise 'pattern missing from file' unless text.include?(pattern) # check before calling gsub!\ntext.gsub!(pattern, replacement)","typeGuard":null,"tryCatchPattern":"begin\n  s.gsub!(pattern, replacement)\nrescue RuntimeError => e\n  raise e unless e.message.start_with?('inreplace:')\n  # handle no-op replacement: log and continue or fall back\nend","preventionTips":["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"],"tags":["ruby","string-substitution","patching","pattern-not-found"],"backgroundTag":"resource-not-found","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}