k1tbyte/Wand-Enhancer · error · Exception

[ENHANCER] [{patchType} -> {patch.Name}] Resolver failed to

Error message

[ENHANCER] [{patchType} -> {patch.Name}] Resolver failed to find field name

What it means

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.

Source

Thrown at WandEnhancer/Core/Enhancer.cs:93

            
            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);
            }
            
            _logger($"{prefix} Found target function in: " + Path.GetFileName(fileName), ELogType.Info);

            string newJs;
            if (patch.PatchFactory != null)
            {
                newJs = patch.SingleMatch
                    ? patch.Target.Replace(js, _ => patchSource, 1)
                    : patch.Target.Replace(js, _ => patchSource);
            }
            else
            {
                newJs = patch.SingleMatch
                    ? patch.Target.Replace(js, patchSource, 1)

View on GitHub (pinned to 643c8f8b62)

Solutions

  1. From [patchType -> Name], find the Resolver.Handler lambda in EnhancerConfig (e.g. EnhancerConfig.cs:113-117 for getUserAccount).
  2. Extract the matched function body from the live app-*.bundle.js (the Target regex will still match it).
  3. Update the Handler's inner Regex to match the new field/access pattern.
  4. 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.
  5. Re-run patch.

Example fix

// before
Handler = (targetFunction) => {
    var m = Regex.Match(targetFunction, @"return\s+this\.\#(\w+)\.fetch");
    return m.Success ? m.Groups[1].Value : null;
}
// after (field access shape changed in new build)
Handler = (targetFunction) => {
    var m = Regex.Match(targetFunction, @"return\s+(?:this\.\#(\w+)|([\w$]+))\.fetch");
    return m.Success ? (m.Groups[1].Value.NullIfEmpty() ?? m.Groups[2].Value) : null;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-test resolver handlers against the matched function body
var entry = EnhancerConfig.GetInstance()[EPatchType.ActivatePro]
    .First(p => p.Name == "getUserAccount");
var m = entry.Target.Match(bundle);
if (m.Success && entry.Resolver != null) {
    var resolved = entry.Resolver.Handler(m.Value);
    if (string.IsNullOrEmpty(resolved))
        _logger("WARN: resolver cannot derive field name on this build.", ELogType.Warning);
}

Try / catch

try {
    enhancer.Patch();
} catch (Exception ex) when (ex.Message.Contains("Resolver failed to find field name")) {
    // inner structure changed while outer anchor survived: re-derive Handler regex
    _logger(ex.Message, ELogType.Error);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


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