{"record":{"id":"23eedc12163e0768","repo":"w7corp/easywechat","slug":"s-cannot-be-empty-r-n","errorCode":null,"errorMessage":"\"%s\" cannot be empty.\\r\\n","messagePattern":"\"(.+?)\" cannot be empty\\.\\\\r\\\\n","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Kernel/Config.php","lineNumber":128,"sourceCode":"    /**\n     * @throws InvalidArgumentException\n     */\n    public function checkMissingKeys(): bool\n    {\n        if (empty($this->requiredKeys)) {\n            return true;\n        }\n\n        $missingKeys = [];\n\n        foreach ($this->requiredKeys as $key) {\n            if (! $this->has($key)) {\n                $missingKeys[] = $key;\n            }\n        }\n\n        if (! empty($missingKeys)) {\n            throw new InvalidArgumentException(sprintf(\"\\\"%s\\\" cannot be empty.\\r\\n\", implode(',', $missingKeys)));\n        }\n\n        return true;\n    }\n}\n","sourceCodeStart":110,"sourceCodeEnd":134,"githubUrl":"https://github.com/w7corp/easywechat/blob/f0cf0a8b8361417ed683b8246d0ecbaf0aafcaa8/src/Kernel/Config.php#L110-L134","documentation":"Thrown by EasyWeChat\\Kernel\\Config::checkMissingKeys() from the Config constructor when one or more required keys are absent from the config array. Each application subclass declares its own requiredKeys: OfficialAccount needs app_id; OpenPlatform needs app_id, secret, aes_key; Work needs corp_id, secret, token, aes_key; Pay needs mch_id, secret_key, private_key, certificate. The message lists exactly which keys are missing (note the check is key existence via Arr::has, not non-empty values).","triggerScenarios":"Instantiating an app whose config array omits a declared key, e.g. creating a Pay client with only mch_id and secret_key (private_key/certificate missing), or an OfficialAccount with ['appid' => 'wx...'] instead of ['app_id' => 'wx...']. Also triggered when config is built from env vars and a missing env var makes the key never get set.","commonSituations":"Typos in key names (appid vs app_id, secret_key vs secret), missing .env entries in a new environment (staging/CI), assuming Pay only needs merchant credentials, forgetting that Work requires token and aes_key even when you only plan API calls.","solutions":["Read the exception message: it names the exact missing keys — add each one to the config array passed to the app factory","Check spelling/case of keys against the app's Config subclass (snake_case: app_id, corp_id, mch_id, secret_key, private_key, certificate, aes_key, token, secret)","For Pay\\erchant: make sure all four of mch_id, secret_key, private_key (path string to apiclient_key.pem) and certificate are provided","Assert required env vars exist before building config (e.g. fail fast when WECHAT_APP_ID is unset instead of silently omitting the key)"],"exampleFix":"// before (OfficialAccount)\n$config = ['app_id' => getenv('WX_APP_ID'), 'secret' => '...'];\n// Fatal: \"app_id\" cannot be empty when env var unset (key absent)\n\n// after\n$config = array_filter([\n    'app_id' => getenv('WX_APP_ID'),\n    'secret' => getenv('WX_SECRET'),\n]);\nif (!isset($config['app_id'])) {\n    throw new RuntimeException('WX_APP_ID env var is not set');\n}","handlingStrategy":"validation","validationCode":"// Before creating the app\n$required = ['app_id']; // OfficialAccount; Work: corp_id, secret, token, aes_key; Pay: mch_id, secret_key, private_key, certificate\n$missing = array_diff($required, array_keys(array_filter($config, fn ($v) => $v !== null && $v !== '')));\nif ($missing) {\n    throw new InvalidArgumentException('Missing WeChat config keys: '.implode(', ', $missing));\n}\n$app = OfficialAccount::create($config); // or new Config($config)","typeGuard":null,"tryCatchPattern":"try {\n    $app = OfficialAccount::create($config);\n} catch (\\EasyWeChat\\Kernel\\Exceptions\\InvalidArgumentException $e) {\n    // message names the missing keys, e.g. \"app_id\" cannot be empty.\n    log_config_error($e->getMessage());\n    fail_deploy_fast();\n}","preventionTips":["Load WeChat credentials from env and validate presence at boot (fail fast), not lazily on first API call","Keep a per-application checklist of required keys next to the factory call","Run a config smoke test in CI for every environment the app deploys to"],"tags":["php","easywechat","config","setup","validation"],"backgroundTag":"missing-required-config","analyzedSha":"f0cf0a8b8361417ed683b8246d0ecbaf0aafcaa8","analyzedAt":"2026-08-21T05:29:19.565Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}