{"record":{"id":"f13952acf7bf85b0","repo":"k1tbyte/Wand-Enhancer","slug":"enhancer-failed-to-apply-patches-failedpatches","errorCode":null,"errorMessage":"[ENHANCER] Failed to apply patches: {failedPatches}. The version may not be supported.","messagePattern":"\\[ENHANCER\\] Failed to apply patches: (.+?)\\. The version may not be supported\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"WandEnhancer/Core/Enhancer.cs","lineNumber":176,"sourceCode":"                        fileChanged = fileChanged || patchApplied;\n                    }\n\n                    if (entries.All(x => x.Applied))\n                    {\n                        remainingPatches.Remove(entry);\n                    }\n                }\n\n                if (fileChanged)\n                {\n                    File.WriteAllText(item, data);\n                }\n            }\n            \n            if(remainingPatches.Count > 0)\n            {\n                var failedPatches = string.Join(\", \", remainingPatches.Select(p => p.ToString()));\n                throw new Exception($\"[ENHANCER] Failed to apply patches: {failedPatches}. The version may not be supported.\");\n            }\n        }\n\n        private static bool IsCandidateBundleFile(string filePath)\n        {\n            string fileName = Path.GetFileName(filePath);\n            return fileName.Equals(IndexBundleFileName, StringComparison.OrdinalIgnoreCase)\n                || (fileName.StartsWith(AppBundleFilePrefix, StringComparison.OrdinalIgnoreCase)\n                    && fileName.EndsWith(AppBundleFileSuffix, StringComparison.OrdinalIgnoreCase));\n        }\n\n        private static bool CouldFileContainRemainingPatch(string filePath, IEnumerable<EPatchType> remainingPatches, Dictionary<EPatchType, EnhancerConfig.PatchEntry[]> enhancerConfig)\n        {\n            foreach (var patchType in remainingPatches)\n            {\n                foreach (var patchEntry in enhancerConfig[patchType])\n                {\n                    if (patchEntry.Applied)","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/k1tbyte/Wand-Enhancer/blob/643c8f8b62cbb26fd3ac105b92497d9a9c445f08/WandEnhancer/Core/Enhancer.cs#L158-L194","documentation":"After scanning every candidate bundle file, PatchAsar still has EPatchType values left in remainingPatches — meaning for at least one requested patch type, not every PatchEntry in EnhancerConfig[type] reached Applied=true (entries.All(x => x.Applied) was false). It is the aggregate 'patch did not fully land' error.","triggerScenarios":"PatchAsar loop completes over all items in `items`; at Enhancer.cs:173 remainingPatches.Count > 0 because one or more patch types never matched (Target.Success false everywhere) or only partially applied (some entries applied, others not).","commonSituations":"A Wand version where some patches still work but others drifted; enabling a PatchType whose anchor method no longer exists in that build; bundle split across files so CandidateFileNames filters miss the right one.","solutions":["Read failedPatches from the message (e.g. 'ActivatePro, DevToolsOnF12').","For each, open its PatchEntry[] in EnhancerConfig.GetInstance() and check Target / SearchHints / CandidateFileNames.","Re-derive the drifted regexes against the live bundle (extract app.asar, grep).","If a patch is optional for your goal, remove that EPatchType from PatchConfig.PatchTypes.","Otherwise upgrade/downgrade Wand to a supported release."],"exampleFix":"// Drop an unsupported patch type from the config to unblock the rest\n// before\nconfig.PatchTypes = new HashSet<EPatchType> {\n    EPatchType.ActivatePro, EPatchType.DisableUpdates, EPatchType.DevToolsOnF12,\n    EPatchType.RemoteWebPanelPreview\n};\n// after (remove the one whose anchor drifted until regex is re-derived)\nconfig.PatchTypes = new HashSet<EPatchType> {\n    EPatchType.ActivatePro, EPatchType.DisableUpdates,\n    EPatchType.RemoteWebPanelPreview\n};","handlingStrategy":"try-catch","validationCode":"// Optional dry run: report which patch types would fail to fully apply\nvar cfg = EnhancerConfig.GetInstance();\nforeach (var type in _config.PatchTypes) {\n    var entries = cfg[type];\n    var anyMissingAnchor = entries.Any(p =>\n        !Directory.EnumerateFiles(_unpackedPath, \"*.js\", SearchOption.TopDirectoryOnly)\n                  .Any(f => p.SearchHints == null || p.SearchHints.Any(h => File.ReadAllText(f).Contains(h))));\n    if (anyMissingAnchor) _logger($\"WARN: {type} anchor not found in any bundle.\", ELogType.Warning);\n}","typeGuard":null,"tryCatchPattern":"try {\n    enhancer.Patch();\n} catch (Exception ex) when (ex.Message.StartsWith(\"[ENHANCER] Failed to apply patches:\")) {\n    // parse failed list, re-derive drifted regexes, or drop optional types\n}","preventionTips":["Run patch types incrementally so one drift does not abort everything.","Surface the per-patch Applied status in the UI before throwing the aggregate.","Pin supported Wand versions and reject others early."],"tags":["version-drift","asar-patch","regex","aggregate"],"backgroundTag":null,"analyzedSha":"643c8f8b62cbb26fd3ac105b92497d9a9c445f08","analyzedAt":"2026-08-13T14:17:43.823Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}