w7corp/easywechat · error · InvalidArgumentException

The method "%s" is not supported.

Error message

The method "%s" is not supported.

What it means

RequestWithPresets::handleMagicWithCall() powers fluent magic setters on API clients — withAppid('wx...'), withAppidAs('sub_appid') — by convention: the method name must start with 'with', the remainder is snake_cased into a preset key. Any name that does not start with 'with' is rejected with InvalidArgumentException listing the unsupported method.

Source

Thrown at src/Kernel/HttpClient/RequestWithPresets.php:167

            $options['headers'] = array_merge($this->prependHeaders, $options['headers'] ?? []);
        }

        $this->prependParts = [];
        $this->prependHeaders = [];

        return $options;
    }

    /**
     * @throws InvalidArgumentException
     */
    public function handleMagicWithCall(string $method, mixed $value = null): static
    {
        // $client->withAppid();
        // $client->withAppid('wxf8b4f85f3a794e77');
        // $client->withAppidAs('sub_appid');
        if (! str_starts_with($method, 'with')) {
            throw new InvalidArgumentException(sprintf('The method "%s" is not supported.', $method));
        }

        $key = Str::snakeCase(substr($method, 4));

        // $client->withAppidAs('sub_appid');
        if (str_ends_with($key, '_as')) {
            $key = substr($key, 0, -3);

            [$key, $value] = [is_string($value) ? $value : $key, $this->presets[$key] ?? null];
        }

        return $this->with($key, $value);
    }
}

View on GitHub (pinned to f0cf0a8b83)

Solutions

  1. Use the 'with' prefix: $client->withFoo($value) — the part after 'with' becomes the preset key 'foo'
  2. To alias a preset to a custom key use withFooAs('custom_key')
  3. For arbitrary keys bypass magic entirely: $client->with('sub_appid', $value)

Example fix

// before
$client->appid('wxf8b4f85f3a794e77'); // routed to handleMagicWithCall -> throws

// after
$client->withAppid('wxf8b4f85f3a794e77');
// or explicit
$client->with('appid', 'wxf8b4f85f3a794e77');
Defensive patterns

Strategy: type-guard

Type guard

// Only route 'with'-prefixed calls to the preset handler
if (method_exists($client, $method) || ! str_starts_with($method, 'with')) {
    return $client->$method(...$args); // normal call, not a preset
}
return $client->handleMagicWithCall($method, ...$args);

Prevention

When it happens

Trigger: Calling $client->handleMagicWithCall('setAppid', ...) or similar directly, or a client's __call forwarding a non-'with' method (e.g. $client->appid('wx...') instead of $client->withAppid('wx...')) into the preset handler.

Common situations: Assuming generic magic setters exist (set/get style) on EasyWeChat request clients, copy-pasting code from other SDKs with different conventions.

Related errors


AI-assisted analysis of w7corp/easywechat@f0cf0a8b83 (2026-08-21). Data as JSON: /api/errors/bd71b39c2868a960. Report an issue: GitHub.