{"record":{"id":"5cdd949ec5d56403","repo":"santifer/career-ops","slug":"apify-token-not-set","errorCode":null,"errorMessage":"APIFY_TOKEN not set","messagePattern":"APIFY_TOKEN not set","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"plugins/apify/_apify.mjs","lineNumber":188,"sourceCode":"}\n\nasync function fetchDatasetItems(runId, token, deadline = null) {\n  const url = `${APIFY_API_BASE}/actor-runs/${runId}/dataset/items`;\n  const items = await fetchJson(\n    url,\n    { headers: authHeaders(token) },\n    PER_REQUEST_TIMEOUT_MS * 2,\n    CONNECT_RETRY_ATTEMPTS,\n    deadline,\n  );\n  if (!Array.isArray(items)) {\n    throw new Error(`Apify run ${runId} returned non-array dataset payload`);\n  }\n  return items;\n}\n\nexport async function runActor(actorId, input, { timeoutMs = DEFAULT_RUN_TIMEOUT_MS, token = process.env.APIFY_TOKEN } = {}) {\n  if (!token) throw new Error('APIFY_TOKEN not set');\n  if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {\n    throw new Error(`apify: invalid timeoutMs ${JSON.stringify(timeoutMs)} (must be a positive finite number of milliseconds)`);\n  }\n  // Single deadline shared across startRun → waitForRun → fetchDatasetItems so\n  // the caller's timeoutMs is the end-to-end ceiling, not just the wait loop.\n  const deadline = Date.now() + timeoutMs;\n  const runId = await startRun(actorId, input, token, deadline);\n  const run = await waitForRun(runId, token, deadline, timeoutMs);\n  if (run.status !== 'SUCCEEDED') {\n    const reason = run.statusMessage ? `: ${run.statusMessage}` : '';\n    throw new Error(`Apify actor ${actorId} finished with status ${run.status}${reason}`);\n  }\n  return await fetchDatasetItems(runId, token, deadline);\n}\n","sourceCodeStart":170,"sourceCodeEnd":203,"githubUrl":"https://github.com/santifer/career-ops/blob/aac998c7ed7248ea853b720ceeb1fdbeb322fc5d/plugins/apify/_apify.mjs#L170-L203","documentation":"runActor requires an Apify API token, taken by default from the APIFY_TOKEN environment variable. If no token is provided (neither via options nor env), the function throws immediately before making any API call.","triggerScenarios":"Calling runActor(actorId, input) without a token option while process.env.APIFY_TOKEN is unset or empty.","commonSituations":"Developer forgot to add APIFY_TOKEN to .env; CI environment lacking the secret; token variable typo'd (APIFY_TOKEN vs APIFY_TOKEN_KEY); running the plugin before enabling it in config.","solutions":["Add APIFY_TOKEN=<token> to your .env file (get a token from the Apify console account settings).","Pass the token explicitly: runActor(actorId, input, { token }).","Ensure your process actually loads .env (e.g. dotenv/config or the app's env loader) before invoking.","Check for typos in the variable name in .env / CI secrets."],"exampleFix":"// .env before\n# (missing)\n// after\nAPIFY_TOKEN=apify_api_XXXXXXXXXXXXXXXX","handlingStrategy":"validation","validationCode":"if (!process.env.APIFY_TOKEN) throw new Error('Set APIFY_TOKEN in .env before running actors');","typeGuard":"const hasApifyToken = () => typeof process.env.APIFY_TOKEN === 'string' && process.env.APIFY_TOKEN.length > 0;","tryCatchPattern":"try {\n  const items = await runActor(actorId, input);\n} catch (e) {\n  if (String(e.message).includes('APIFY_TOKEN not set')) {\n    console.error('Configure APIFY_TOKEN in .env');\n    return [];\n  }\n  throw e;\n}","preventionTips":["Add APIFY_TOKEN to .env and commit only .env.example.","Check env presence at app startup with a fail-fast config check.","In CI, add APIFY_TOKEN to the secrets store.","Pass the token explicitly in library-embedding code rather than relying on env."],"tags":["apify","env","auth","token"],"backgroundTag":"missing-env-var","analyzedSha":"aac998c7ed7248ea853b720ceeb1fdbeb322fc5d","analyzedAt":"2026-09-16T06:35:29.214Z","contentChangedAt":"2026-09-16T06:35:29.214Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}