{"record":{"id":"c4085f29bc379e62","repo":"k1tbyte/Wand-Enhancer","slug":"enhancer-patchtype-patch-name-patch-fai","errorCode":null,"errorMessage":"[ENHANCER] [{patchType} -> {patch.Name}] Patch failed. Multiple target functions found. Looks like the version is not supported","messagePattern":"\\[ENHANCER\\] \\[(.+?) -> (.+?)\\] Patch failed\\. Multiple target functions found\\. Looks like the version is not supported","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"WandEnhancer/Core/Enhancer.cs","lineNumber":80,"sourceCode":"                return js;\n            }\n\n            if (!CanSearchPatchInFile(fileName, patch) || !ContainsSearchHint(js, patch.SearchHints))\n            {\n                return js;\n            }\n            \n            var match = patch.Target.Match(js);\n            if (!match.Success)\n            {\n                return js;\n            }\n            \n            var prefix = $\"[ENHANCER] [{patchType} -> {patch.Name}]\";\n            \n            if(patch.SingleMatch && match.NextMatch().Success)\n            {\n                throw new Exception(\n                    $\"{prefix} Patch failed. Multiple target functions found. Looks like the version is not supported\");\n            }\n\n            string patchSource = patch.PatchFactory != null\n                ? patch.PatchFactory(match)\n                : patch.Patch;\n\n            if (patch.Resolver != null)\n            {\n                string resolvedField = patch.Resolver.Handler(match.Value);\n                if (string.IsNullOrEmpty(resolvedField))\n                {\n                    throw new Exception($\"{prefix} Resolver failed to find field name\");\n                }\n                \n                patchSource = patchSource.Replace(patch.Resolver.Placeholder, resolvedField);\n            }\n            ","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/k1tbyte/Wand-Enhancer/blob/643c8f8b62cbb26fd3ac105b92497d9a9c445f08/WandEnhancer/Core/Enhancer.cs#L62-L98","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["From the message's [patchType -> Name], locate the PatchEntry.Target in EnhancerConfig.GetInstance() (e.g. ActivatePro/getUserAccount at EnhancerConfig.cs:121).","Extract the live app.asar and open app-*.bundle.js; grep for the anchor to see both match sites.","Tighten the Target regex with more surrounding context (return shape, fetch URL, private-field access) so it matches exactly once.","If multiple genuine matches are expected and intended, set SingleMatch = false on that PatchEntry.","Otherwise pin Wand to a supported version."],"exampleFix":"// before (matches twice on new build)\nTarget = new Regex(@\"getUserAccount\\(\\)\\{\")\n// after (anchored to the unique fetch site)\nTarget = new Regex(@\"getUserAccount\\(\\)\\{.*?return\\s+this\\.\\#\\w+\\.fetch\\(\\{.*?\\}\\)\\)\",\n           RegexOptions.Singleline)\n// or, when multiple real matches are intended:\nnew PatchEntry { SingleMatch = false, Target = ..., Patch = ... }","handlingStrategy":"try-catch","validationCode":"// Pre-test each SingleMatch patch for uniqueness on the extracted bundle\nstring bundle = File.ReadAllText(candidateBundlePath);\nforeach (var (type, entries) in EnhancerConfig.GetInstance()) {\n    if (!_config.PatchTypes.Contains(type)) continue;\n    foreach (var p in entries.Where(e => e.SingleMatch)) {\n        var m = p.Target.Match(bundle);\n        if (m.Success && m.NextMatch().Success)\n            _logger($\"WARN: {p.Name} matches multiple sites; regex needs tightening.\", ELogType.Warning);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    enhancer.Patch();\n} catch (Exception ex) when (ex.Message.Contains(\"Multiple target functions found\")) {\n    // version drift: surface to user, offer Wand downgrade or regex re-derive\n    _logger(ex.Message, ELogType.Error);\n}","preventionTips":["Maintain a CI step that runs EnhancerConfig regexes against the latest Wand bundle and fails on multi-match.","Keep SingleMatch = true (default) so ambiguity is loud, not silent.","Anchor every Target regex on stable tokens (URLs, dispatch strings) rather than mangled identifiers.","Track supported Wand versions in release notes and reject unknown versions before patching."],"tags":["regex","version-drift","asar-patch","single-match"],"backgroundTag":null,"analyzedSha":"643c8f8b62cbb26fd3ac105b92497d9a9c445f08","analyzedAt":"2026-08-13T14:17:43.823Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}