{"record":{"id":"c2e8ba33a60e1ea0","repo":"koala73/worldmonitor","slug":"set-sentry-api-token-or-sentry-auth-token-sentry-session","errorCode":null,"errorMessage":"Set SENTRY_API_TOKEN (or SENTRY_AUTH_TOKEN / SENTRY_SESSION_TOKEN) to a sntryu_ user token with project:read and project:write.","messagePattern":"Set SENTRY_API_TOKEN \\(or SENTRY_AUTH_TOKEN / SENTRY_SESSION_TOKEN\\) to a sntryu_ user token with project:read and project:write\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/sync-sentry-convex-probe-filters.mjs","lineNumber":397,"sourceCode":"  }\n  if (extra.length > 0) {\n    parts.push(`  Extra (${extra.length}):`);\n    for (const line of extra.slice(0, 20)) parts.push(`    - ${line}`);\n    if (extra.length > 20) parts.push(`    … and ${extra.length - 20} more`);\n  }\n  throw new Error(parts.join('\\n'));\n}\n\n/**\n * Merge generated patterns into live Sentry filters, PUT, and read back.\n *\n * @param {string[]} patterns\n * @param {{ dryRun: boolean }} opts\n */\nasync function runApply(patterns, opts) {\n  const token = resolveToken();\n  if (!token) {\n    throw new Error(\n      'Set SENTRY_API_TOKEN (or SENTRY_AUTH_TOKEN / SENTRY_SESSION_TOKEN) to a '\n        + 'sntryu_ user token with project:read and project:write.',\n    );\n  }\n  const org = process.env.SENTRY_ORG || DEFAULT_ORG;\n  const project = process.env.SENTRY_PROJECT || DEFAULT_PROJECT;\n\n  const before = await fetchProjectOptions(token, org, project);\n  const options = /** @type {Record<string, unknown>} */ (before.options ?? {});\n  const currentText =\n    typeof options['filters:error_messages'] === 'string'\n      ? options['filters:error_messages']\n      : '';\n  const currentLines = splitErrorMessageFilters(currentText);\n  const { merged, appended, removed, preservedOther } = mergeErrorMessageFilters(\n    currentLines,\n    patterns,\n  );","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/koala73/worldmonitor/blob/e586b8b4b80f595aa7ece295eec10d76f2921240/scripts/sync-sentry-convex-probe-filters.mjs#L379-L415","documentation":"runApply resolves the Sentry token from SENTRY_API_TOKEN / SENTRY_AUTH_TOKEN / SENTRY_SESSION_TOKEN and throws when none is set, telling the user exactly what kind of token is needed: a sntryu_ user token with project:read and project:write. The sync cannot read or write project options without credentials.","triggerScenarios":"Running the apply/sync command in an environment where none of the three token env vars is set — local shell without .env loaded, CI job missing the secret, or the variable defined under a different name.","commonSituations":"Secrets not injected in CI, .env file not sourced, token var renamed in CI config, or only an org-level sntrys_ token available which resolveToken rejects or which lacks the needed scopes.","solutions":["Set SENTRY_API_TOKEN to a sntryu_ user token with project:read and project:write.","If using SENTRY_AUTH_TOKEN or SENTRY_SESSION_TOKEN instead, ensure it is a user token with both scopes.","In CI, add the token as a secret and pass it into the step environment.","Run through the repo's loadEnvFile() path so local .env credentials are picked up."],"exampleFix":"// before\nnpx node scripts/sync-sentry-convex-probe-filters.mjs apply   // no token in env\n// after\nSENTRY_API_TOKEN=sntryu_xxx npm run sync:sentry-convex-probe-filters","handlingStrategy":"validation","validationCode":"const token = process.env.SENTRY_API_TOKEN || process.env.SENTRY_AUTH_TOKEN || process.env.SENTRY_SESSION_TOKEN;\nif (!token) { console.error('Set SENTRY_API_TOKEN (sntryu_ user token, project:read+write)'); process.exit(1); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Store the token as a CI secret and export it in the job environment.","Source the local .env via loadEnvFile() before running scripts.","Document required env vars in the script's usage banner."],"tags":["environment","sentry","credentials","cli"],"backgroundTag":"missing-env-var","analyzedSha":"e586b8b4b80f595aa7ece295eec10d76f2921240","analyzedAt":"2026-09-22T01:50:49.965Z","contentChangedAt":"2026-09-22T01:50:49.965Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}