{"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/533346cc374382b41ec5ff70536252b2e96e725c/src/system/packages/brew/shim.rb#L859-L895","documentation":"Raised by the Inreplace helper's gsub! when the search pattern does not occur in the text being patched and the audit_result flag is true (the default). mise's brew shim uses this class to apply small textual patches to Homebrew formulae/casks during source builds, and it treats a non-matching pattern as an error because a silent no-op patch would produce an unmodified build. It guards against formulae whose content changed upstream so a patch would be silently skipped.","triggerScenarios":"Calling gsub!(pattern, replacement) on an Inreplace where the pattern is absent from the text; the source formula/cask was updated upstream so the expected line or string no longer exists; a patch written for one formula version is applied to a different version; passing audit_result=false avoids the raise but returns nil instead.","commonSituations":"Building a tool from source via a brew tap after Homebrew updated the formula; a pinned patch in mise's brew shim drifting from the current formula contents; typos or over-specific regexes that fail on whitespace/quote variants of the expected text.","solutions":["Update or remove the stale patch/pattern so it matches the current formula/cask contents","Pin the tool to a formula/cask version the patch was written for","Inspect the target file and adjust the regex to tolerate formatting differences (whitespace, quoting)","Pass audit_result=false only if a no-op patch is intentionally acceptable"],"exampleFix":"# before\nf.gsub!(\"depends_on \\\"openssl@1.1\\\"\", \"depends_on \\\"openssl@3\\\"\")\n# after\nif f.text.include?(\"depends_on \\\"openssl@1.1\\\"\")\n  f.gsub!(\"depends_on \\\"openssl@1.1\\\"\", \"depends_on \\\"openssl@3\\\"\")\nelse\n  # formula already updated; skip patch\nend","handlingStrategy":"validation","validationCode":"raise \"patch target missing\" unless inreplace.text.include?(pattern)\ninreplace.gsub!(pattern, replacement)","typeGuard":"def patchable?(inreplace, pattern) = !inreplace.text.scan(pattern).empty?","tryCatchPattern":"begin\n  f.gsub!(pattern, replacement)\nrescue RuntimeError => e\n  raise unless e.message.start_with?(\"inreplace:\")\n  warn \"patch no longer applies: #{e.message}; skipping\"\nend","preventionTips":["Anchor patches to version-stable text and re-check after every formula update","Prefer narrow, unique patterns and verify with include? before gsub!","Pass audit_result=false only for truly optional patches","Test the shim against the exact formula revision being installed"],"tags":["ruby","patching","regex","brew-formula"],"backgroundTag":"pattern-not-found","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"}