k1tbyte/Wand-Enhancer · error · Exception

[ENHANCER] [{patchType} -> {patch.Name}] Patch failed. Multi

Error message

[ENHANCER] [{patchType} -> {patch.Name}] Patch failed. Multiple target functions found. Looks like the version is not supported

What it means

A JS patch whose PatchEntry.SingleMatch is true (the default) had its Target regex match more than one location in the unpacked bundle. ApplyJsPatch refuses to rewrite ambiguous sites because blindly replacing both would corrupt unrelated code. The message names patchType and patch.Name so the drifted regex is identifiable.

Source

Thrown at WandEnhancer/Core/Enhancer.cs:80

                return js;
            }

            if (!CanSearchPatchInFile(fileName, patch) || !ContainsSearchHint(js, patch.SearchHints))
            {
                return js;
            }
            
            var match = patch.Target.Match(js);
            if (!match.Success)
            {
                return js;
            }
            
            var prefix = $"[ENHANCER] [{patchType} -> {patch.Name}]";
            
            if(patch.SingleMatch && match.NextMatch().Success)
            {
                throw new Exception(
                    $"{prefix} Patch failed. Multiple target functions found. Looks like the version is not supported");
            }

            string patchSource = patch.PatchFactory != null
                ? patch.PatchFactory(match)
                : patch.Patch;

            if (patch.Resolver != null)
            {
                string resolvedField = patch.Resolver.Handler(match.Value);
                if (string.IsNullOrEmpty(resolvedField))
                {
                    throw new Exception($"{prefix} Resolver failed to find field name");
                }
                
                patchSource = patchSource.Replace(patch.Resolver.Placeholder, resolvedField);
            }
            

View on GitHub (pinned to 643c8f8b62)

Solutions

  1. From the message's [patchType -> Name], locate the PatchEntry.Target in EnhancerConfig.GetInstance() (e.g. ActivatePro/getUserAccount at EnhancerConfig.cs:121).
  2. Extract the live app.asar and open app-*.bundle.js; grep for the anchor to see both match sites.
  3. Tighten the Target regex with more surrounding context (return shape, fetch URL, private-field access) so it matches exactly once.
  4. If multiple genuine matches are expected and intended, set SingleMatch = false on that PatchEntry.
  5. Otherwise pin Wand to a supported version.

Example fix

// before (matches twice on new build)
Target = new Regex(@"getUserAccount\(\)\{")
// after (anchored to the unique fetch site)
Target = new Regex(@"getUserAccount\(\)\{.*?return\s+this\.\#\w+\.fetch\(\{.*?\}\)\)",
           RegexOptions.Singleline)
// or, when multiple real matches are intended:
new PatchEntry { SingleMatch = false, Target = ..., Patch = ... }
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-test each SingleMatch patch for uniqueness on the extracted bundle
string bundle = File.ReadAllText(candidateBundlePath);
foreach (var (type, entries) in EnhancerConfig.GetInstance()) {
    if (!_config.PatchTypes.Contains(type)) continue;
    foreach (var p in entries.Where(e => e.SingleMatch)) {
        var m = p.Target.Match(bundle);
        if (m.Success && m.NextMatch().Success)
            _logger($"WARN: {p.Name} matches multiple sites; regex needs tightening.", ELogType.Warning);
    }
}

Try / catch

try {
    enhancer.Patch();
} catch (Exception ex) when (ex.Message.Contains("Multiple target functions found")) {
    // version drift: surface to user, offer Wand downgrade or regex re-derive
    _logger(ex.Message, ELogType.Error);
}

Prevention

When it happens

Trigger: Enhancer.Patch() -> PatchAsar -> ApplyJsPatch where match = patch.Target.Match(js) succeeds and match.NextMatch().Success is also true, while patch.SingleMatch == true. Happens when a Wand release duplicated the anchor (e.g. getUserAccount appears in a base class and subclass) or the Target regex is too loose.

Common situations: Patching an untested/newer Wand build where the minified app-*.bundle.js reshaped a method the regex was anchored to; a regex that was tight on one build but matches two sites on another; copy-pasted method bodies in the bundle.

Related errors


AI-assisted analysis of k1tbyte/Wand-Enhancer@643c8f8b62 (2026-08-13). Data as JSON: /api/errors/c4085f29bc379e62. Report an issue: GitHub.