koala73/worldmonitor · error

Set SENTRY_API_TOKEN (or SENTRY_AUTH_TOKEN /…

Error message

Set SENTRY_API_TOKEN (or SENTRY_AUTH_TOKEN / SENTRY_SESSION_TOKEN) to a sntryu_ user token with project:read and project:write.

What it means

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.

Solutions

  1. Set SENTRY_API_TOKEN to a sntryu_ user token with project:read and project:write.
  2. If using SENTRY_AUTH_TOKEN or SENTRY_SESSION_TOKEN instead, ensure it is a user token with both scopes.
  3. In CI, add the token as a secret and pass it into the step environment.
  4. Run through the repo's loadEnvFile() path so local .env credentials are picked up.

Example fix

// before
npx node scripts/sync-sentry-convex-probe-filters.mjs apply   // no token in env
// after
SENTRY_API_TOKEN=sntryu_xxx npm run sync:sentry-convex-probe-filters
Defensive patterns

Strategy: validation

Validate before calling

const token = process.env.SENTRY_API_TOKEN || process.env.SENTRY_AUTH_TOKEN || process.env.SENTRY_SESSION_TOKEN;
if (!token) { console.error('Set SENTRY_API_TOKEN (sntryu_ user token, project:read+write)'); process.exit(1); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of koala73/worldmonitor@e586b8b4b8 (2026-09-22). Data as JSON: /api/errors/c2e8ba33a60e1ea0. Report an issue: GitHub.

Appendix: source

Thrown at scripts/sync-sentry-convex-probe-filters.mjs:397

  }
  if (extra.length > 0) {
    parts.push(`  Extra (${extra.length}):`);
    for (const line of extra.slice(0, 20)) parts.push(`    - ${line}`);
    if (extra.length > 20) parts.push(`    … and ${extra.length - 20} more`);
  }
  throw new Error(parts.join('\n'));
}

/**
 * Merge generated patterns into live Sentry filters, PUT, and read back.
 *
 * @param {string[]} patterns
 * @param {{ dryRun: boolean }} opts
 */
async function runApply(patterns, opts) {
  const token = resolveToken();
  if (!token) {
    throw new Error(
      'Set SENTRY_API_TOKEN (or SENTRY_AUTH_TOKEN / SENTRY_SESSION_TOKEN) to a '
        + 'sntryu_ user token with project:read and project:write.',
    );
  }
  const org = process.env.SENTRY_ORG || DEFAULT_ORG;
  const project = process.env.SENTRY_PROJECT || DEFAULT_PROJECT;

  const before = await fetchProjectOptions(token, org, project);
  const options = /** @type {Record<string, unknown>} */ (before.options ?? {});
  const currentText =
    typeof options['filters:error_messages'] === 'string'
      ? options['filters:error_messages']
      : '';
  const currentLines = splitErrorMessageFilters(currentText);
  const { merged, appended, removed, preservedOther } = mergeErrorMessageFilters(
    currentLines,
    patterns,
  );

View on GitHub (pinned to e586b8b4b8)