Hmbown/CodeWhale · error · Error
CF_ACCOUNT_ID and CF_API_TOKEN are required
Error message
CF_ACCOUNT_ID and CF_API_TOKEN are required
What it means
main() requires CF_ACCOUNT_ID and CF_API_TOKEN (both trimmed) from the environment and throws this message before any request when either is missing or blank. These are the script's only credential source; parseArgs has already succeeded by this point.
Source
Thrown at telemetry-ingest/scripts/report-active-installs.mjs:220
headers: {
Authorization: `Bearer ${apiToken}`,
"content-type": "text/plain; charset=utf-8",
},
body: sql,
});
if (!response.ok) {
const body = (await response.text()).slice(0, 500);
throw new Error(`Cloudflare SQL request failed (${response.status}): ${body}`);
}
return response.json();
}
export async function main(argv = process.argv.slice(2), env = process.env) {
const { days, json } = parseArgs(argv);
const accountId = env.CF_ACCOUNT_ID?.trim();
const apiToken = env.CF_API_TOKEN?.trim();
if (!accountId || !apiToken) {
throw new Error("CF_ACCOUNT_ID and CF_API_TOKEN are required");
}
const rows = rowsFromResponse(
await querySql({ accountId, apiToken, sql: activeInstallsSql(days) }),
);
const newestEvent = newestEventFromResponse(
await querySql({ accountId, apiToken, sql: freshnessSql() }),
);
const now = new Date();
if (json) {
process.stdout.write(
`${JSON.stringify(
{
metric: "observed_active_installs",
timezone: "UTC",
days,
rows,
trend: trendSummary(rows, days, now),
freshness: {View on GitHub (pinned to 8880682c63)
Solutions
- Export both values obtained from the Cloudflare dashboard (account id) and a token with SQL read scope
- In CI, add them as masked secrets wired into the step's env
- Verify with `printenv CF_ACCOUNT_ID CF_API_TOKEN` before rerunning
Example fix
# before node scripts/report-active-installs.mjs --json # after CF_ACCOUNT_ID=abc CF_API_TOKEN=xyz node scripts/report-active-installs.mjs --json
Defensive patterns
Strategy: validation
Validate before calling
for (const name of ['CF_ACCOUNT_ID', 'CF_API_TOKEN']) {
if (!process.env[name]?.trim()) {
console.error(`${name} is required`);
process.exit(2);
}
} Try / catch
try {
await main(argv, env);
} catch (error) {
if (/CF_ACCOUNT_ID and CF_API_TOKEN are required/.test(error.message)) { process.exit(2); }
throw error;
} Prevention
- Wire the two names as CI masked secrets and fail the job early when absent
- Keep a checked-in example env file listing required telemetry credentials
When it happens
Trigger: Running report-active-installs.mjs in a shell or CI step without exporting the two variables, or with whitespace-only values.
Common situations: Local run without sourcing the secrets file; CI job missing the injected secrets; a token deleted during rotation but the env file not updated.
Related errors
- ${name} is required
- ${name} is required
- ${names.join(" or ")} is required
- ${name} is required
- No local {} API key was found in config, the secret store, o
AI-assisted analysis of Hmbown/CodeWhale@8880682c63 (2026-08-16).
Data as JSON: /api/errors/82deb051becac09d.
Report an issue: GitHub.