{"record":{"id":"47a53c32df4b14a2","repo":"jackwener/OpenCLI","slug":"weread-api-key-is-not-set-export-it-with-export","errorCode":null,"errorMessage":"WEREAD_API_KEY is not set. Export it with `export WEREAD_API_KEY=<wrk-...>`.","messagePattern":"WEREAD_API_KEY is not set\\. Export it with `export WEREAD_API_KEY=<wrk-\\.\\.\\.>`\\.","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"critical","filePath":"clis/weread-official/utils.js","lineNumber":39,"sourceCode":"export const WEREAD_GATEWAY_URL = 'https://i.weread.qq.com/api/agent/gateway';\nexport const WEREAD_DOMAIN = 'weread.qq.com';\n\n/**\n * Skill version reported with every gateway request. Bump when official\n * `weread-skills.zip` ships a new SKILL.md `version:` line.\n */\nexport const SKILL_VERSION = '1.0.4';\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\n\n/** errcodes that mean \"Bearer key invalid / token expired\" — map to AuthRequiredError. */\nconst AUTH_ERRCODES = new Set([-2010, -2012]);\n\n/** Resolve API key from env. Throws AuthRequiredError on missing / blank value. */\nexport function getApiKey() {\n    const key = String(process.env.WEREAD_API_KEY ?? '').trim();\n    if (!key) {\n        throw new AuthRequiredError(\n            WEREAD_DOMAIN,\n            'WEREAD_API_KEY is not set. Export it with `export WEREAD_API_KEY=<wrk-...>`.',\n        );\n    }\n    return key;\n}\n\n/**\n * Build the gateway request body. Business params are flattened next to\n * `api_name` and `skill_version` — never wrapped in a `params` / `data` /\n * `body` object (the gateway silently drops them and returns page 1).\n */\nexport function buildGatewayBody(apiName, params = {}) {\n    if (!apiName || typeof apiName !== 'string') {\n        throw new ArgumentError('weread-official: api_name is required');\n    }\n    const body = { api_name: apiName, skill_version: SKILL_VERSION };\n    for (const [key, value] of Object.entries(params ?? {})) {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/weread-official/utils.js#L21-L57","documentation":"getApiKey() reads WEREAD_API_KEY from the environment and throws AuthRequiredError when it is missing or blank after trimming. The WeRead official API requires a wrk- prefixed key on every request, so the client fails fast before making any network call. The message shows the exact export command to fix it.","triggerScenarios":"Running the CLI in a shell where WEREAD_API_KEY was never exported; exporting it only in another shell/session/CI job; key set as empty string or whitespace; dotenv file not loaded; running under systemd/cron/Docker where the env var wasn't propagated.","commonSituations":"New machine setup where the key was never configured; CI pipelines missing the secret in the environment settings; switching from a .env-based tool to this CLI that reads process.env directly; sudo or subshell dropping the variable.","solutions":["Run `export WEREAD_API_KEY=<wrk-...>` in the current shell before invoking the command","Add the export to ~/.bashrc / ~/.zshrc so it persists across sessions","In CI, add WEREAD_API_KEY to the pipeline/secret manager environment settings","If using a .env file, ensure it's loaded into the environment before the CLI runs","Verify with `echo ${WEREAD_API_KEY:+set}` that the variable is non-empty"],"exampleFix":"// before (fails)\nawait wereadSearch({ keyword: '三体' });\n// after\nif (!process.env.WEREAD_API_KEY) {\n  throw new Error('WEREAD_API_KEY is not set. Export it with `export WEREAD_API_KEY=<wrk-...>`.');\n}\nawait wereadSearch({ keyword: '三体' });","handlingStrategy":"validation","validationCode":"if (!String(process.env.WEREAD_API_KEY ?? '').trim()) {\n  throw new Error('WEREAD_API_KEY is not set. Export it with `export WEREAD_API_KEY=<wrk-...>`.');\n}","typeGuard":"function hasApiKey() { return String(process.env.WEREAD_API_KEY ?? '').trim().length > 0; }","tryCatchPattern":"try { await wereadCall(); }\ncatch (e) { if (e.name === 'AuthRequiredError') { console.error('Set WEREAD_API_KEY first: export WEREAD_API_KEY=<wrk-...>'); process.exit(1); } throw e; }","preventionTips":["Export WEREAD_API_KEY in your shell profile","Add the secret to CI environment settings","Fail fast with a startup check before running commands","Verify non-empty after switching shells, sudo, or containers"],"tags":["authentication","missing-env-var","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}