{"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":"exception","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/9b17a8ac97b398a496b38e423ae24e433b43254f/plugins/apify/_apify.mjs#L170-L203","documentation":"Thrown by `runActor` (plugins/apify/_apify.mjs:188) at the very top of the function when no token is supplied. The token defaults to `process.env.APIFY_TOKEN`; if that is unset AND no explicit `token` option is passed, the function refuses to proceed before making any network call. This prevents an anonymous request that would silently fail later. Note the provider-level wrapper (index.mjs) has its own richer message (error 115); this lower-level guard catches direct callers of runActor.","triggerScenarios":"`runActor(actorId, input)` or `runActor(actorId, input, {})` is called when `process.env.APIFY_TOKEN` is undefined/empty. The guard `if (!token)` fires immediately.","commonSituations":"Running a script that calls runActor directly without loading .env; CI environment missing the secret; .env not loaded because the process was started without the env loader; the provider plugin's ctx.env did not propagate the token to a direct runActor call.","solutions":["Set APIFY_TOKEN in .env and ensure the env loader runs before calling runActor.","Pass the token explicitly: `runActor(actorId, input, { token })`.","In CI, inject APIFY_TOKEN as a secret environment variable.","Verify with `node -e \"console.log(Boolean(process.env.APIFY_TOKEN))\"` in the same process context."],"exampleFix":"// before\nimport { runActor } from './plugins/apify/_apify.mjs';\nawait runActor('misceres/indeed-scraper', {}); // throws: APIFY_TOKEN not set\n// after\nimport 'dotenv/config';\nawait runActor('misceres/indeed-scraper', {}); // token read from process.env.APIFY_TOKEN","handlingStrategy":"validation","validationCode":"function assertApifyToken(env = process.env) {\n  if (!env.APIFY_TOKEN) {\n    throw new Error('APIFY_TOKEN missing — add it to .env before running apify scans.');\n  }\n}\nassertApifyToken();","typeGuard":"/** @param {unknown} env */\nfunction hasApifyToken(env) {\n  return typeof env?.APIFY_TOKEN === 'string' && env.APIFY_TOKEN.length > 0;\n}","tryCatchPattern":"if (!process.env.APIFY_TOKEN) {\n  console.error('Skipping apify scan: APIFY_TOKEN not set. Add it to .env.');\n} else {\n  await runActor(actorId, input, opts);\n}","preventionTips":["Load .env (e.g. dotenv) before any apify call.","Inject APIFY_TOKEN as a CI secret and fail the job early if absent."],"tags":["apify","configuration","environment","auth","secrets"],"backgroundTag":null,"analyzedSha":"9b17a8ac97b398a496b38e423ae24e433b43254f","analyzedAt":"2026-08-13T00:48:39.135Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}