{"record":{"id":"9e006f326316b274","repo":"k1tbyte/Wand-Enhancer","slug":"enhancer-patchtype-patch-name-resolver","errorCode":null,"errorMessage":"[ENHANCER] [{patchType} -> {patch.Name}] Resolver failed to find field name","messagePattern":"\\[ENHANCER\\] \\[(.+?) -> (.+?)\\] Resolver failed to find field name","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"WandEnhancer/Core/Enhancer.cs","lineNumber":93,"sourceCode":"            \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            \n            _logger($\"{prefix} Found target function in: \" + Path.GetFileName(fileName), ELogType.Info);\n\n            string newJs;\n            if (patch.PatchFactory != null)\n            {\n                newJs = patch.SingleMatch\n                    ? patch.Target.Replace(js, _ => patchSource, 1)\n                    : patch.Target.Replace(js, _ => patchSource);\n            }\n            else\n            {\n                newJs = patch.SingleMatch\n                    ? patch.Target.Replace(js, patchSource, 1)","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/k1tbyte/Wand-Enhancer/blob/643c8f8b62cbb26fd3ac105b92497d9a9c445f08/WandEnhancer/Core/Enhancer.cs#L75-L111","documentation":"The patch has a ResolveContext whose Handler function extracts a runtime-private field name (e.g. the service identifier behind this.#xxx.fetch) from the matched function body, to substitute into the patch template's Placeholder. The Handler returned null or empty string, so the placeholder could not be filled. The outer Target regex still matched, but the inner structure of the matched function changed.","triggerScenarios":"ApplyJsPatch at Enhancer.cs:90 calls patch.Resolver.Handler(match.Value); for ActivatePro/getUserAccount the Handler runs Regex.Match(targetFunction, @\"return\\s+this\\.#(\\w+)\\.fetch\") and returns Groups[1].Value, or null if it fails. A null/empty return triggers the throw at Enhancer.cs:93.","commonSituations":"A Wand build partially refactored the account service: the outer function signature survived (Target still matches) but the internal fetch helper identifier pattern changed (e.g. switched from this.#svc.fetch to a direct call, or renamed the private field).","solutions":["From [patchType -> Name], find the Resolver.Handler lambda in EnhancerConfig (e.g. EnhancerConfig.cs:113-117 for getUserAccount).","Extract the matched function body from the live app-*.bundle.js (the Target regex will still match it).","Update the Handler's inner Regex to match the new field/access pattern.","If the field genuinely cannot be derived, switch the patch to a PatchFactory that captures the identifier via a named group on the outer Target instead.","Re-run patch."],"exampleFix":"// before\nHandler = (targetFunction) => {\n    var m = Regex.Match(targetFunction, @\"return\\s+this\\.\\#(\\w+)\\.fetch\");\n    return m.Success ? m.Groups[1].Value : null;\n}\n// after (field access shape changed in new build)\nHandler = (targetFunction) => {\n    var m = Regex.Match(targetFunction, @\"return\\s+(?:this\\.\\#(\\w+)|([\\w$]+))\\.fetch\");\n    return m.Success ? (m.Groups[1].Value.NullIfEmpty() ?? m.Groups[2].Value) : null;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-test resolver handlers against the matched function body\nvar entry = EnhancerConfig.GetInstance()[EPatchType.ActivatePro]\n    .First(p => p.Name == \"getUserAccount\");\nvar m = entry.Target.Match(bundle);\nif (m.Success && entry.Resolver != null) {\n    var resolved = entry.Resolver.Handler(m.Value);\n    if (string.IsNullOrEmpty(resolved))\n        _logger(\"WARN: resolver cannot derive field name on this build.\", ELogType.Warning);\n}","typeGuard":null,"tryCatchPattern":"try {\n    enhancer.Patch();\n} catch (Exception ex) when (ex.Message.Contains(\"Resolver failed to find field name\")) {\n    // inner structure changed while outer anchor survived: re-derive Handler regex\n    _logger(ex.Message, ELogType.Error);\n}","preventionTips":["Resolver handlers should be defensive and return null only after exhausting several patterns.","Prefer PatchFactory with a named capture on the outer Target over a separate Resolver regex.","Add a CI probe that asserts each Resolver yields a non-empty value on the current bundle."],"tags":["regex","version-drift","resolver","asar-patch"],"backgroundTag":null,"analyzedSha":"643c8f8b62cbb26fd3ac105b92497d9a9c445f08","analyzedAt":"2026-08-13T14:17:43.823Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}