{"record":{"id":"18418c899a716212","repo":"koala73/worldmonitor","slug":"use-plan-check-or-apply","errorCode":null,"errorMessage":"Use --plan, --check, or --apply","messagePattern":"Use --plan, --check, or --apply","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/cloudflare-agent-readiness.mjs","lineNumber":46,"sourceCode":"      content_type: 'application/json',\n      content: JSON.stringify(policy.blockedResponse),\n    };\n    if (!isDeepStrictEqual(rule.action_parameters?.response, response)) {\n      const definition = Object.fromEntries(Object.entries(rule).filter(([key]) =>\n        !['id', 'version', 'last_updated'].includes(key)));\n      changes.push({\n        phase: FIREWALL_PHASE, rulesetId: firewall.id, ruleId: rule.id,\n        description, method: 'PATCH',\n        body: { ...definition, action_parameters: { ...rule.action_parameters, response } },\n      });\n    }\n  }\n\n  return changes;\n}\n\nexport async function runAgentReadiness(mode, { env = process.env, fetchImpl } = {}) {\n  if (!['--plan', '--check', '--apply'].includes(mode)) throw new Error('Use --plan, --check, or --apply');\n  const token = resolveToken(env);\n  const zoneId = await resolveZoneId(token, { env, fetchImpl });\n  const read = (phase) => cloudflareRequest(`/zones/${zoneId}/rulesets/phases/${phase}/entrypoint`, { token, fetchImpl });\n  const firewall = await read(FIREWALL_PHASE);\n  const changes = planAgentReadiness(firewall);\n  if (mode !== '--apply' || changes.length === 0) return { zone: 'worldmonitor.app', ready: changes.length === 0, changes };\n\n  for (const change of changes) {\n    const current = await read(change.phase);\n    if (!isDeepStrictEqual(current.rules, firewall.rules)) {\n      throw new Error('Cloudflare rules changed after planning. Run --plan again before applying.');\n    }\n    const updated = await cloudflareRequest(`/zones/${zoneId}/rulesets/${change.rulesetId}/rules/${change.ruleId}`, {\n      token, fetchImpl, method: change.method, body: change.body,\n    });\n    firewall.rules = updated.rules;\n  }\n  const remaining = planAgentReadiness(await read(FIREWALL_PHASE));","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/koala73/worldmonitor/blob/7d06c8633d256c18e38133030bc3613976a96ec9/scripts/cloudflare-agent-readiness.mjs#L28-L64","documentation":"runAgentReadiness only accepts one of three CLI modes: --plan, --check, or --apply. It throws immediately when mode is anything else, before resolving the token or contacting Cloudflare. This is the entry-point argument validation for the readiness script.","triggerScenarios":"Invoking the script with no mode (undefined), a misspelled flag like --plane or -plan, or an extra/unexpected argv value.","commonSituations":"Typo in the flag when running node scripts/cloudflare-agent-readiness.mjs, calling the exported function programmatically with the wrong argument, or omitting the mode entirely.","solutions":["Run the script with exactly one of: --plan, --check, or --apply.","Check for typos or extra arguments after the mode flag.","If calling runAgentReadiness from code, pass the literal flag string (e.g. runAgentReadiness('--check'))."],"exampleFix":"// before\nnode scripts/cloudflare-agent-readiness.mjs --chek\n// after\nnode scripts/cloudflare-agent-readiness.mjs --check","handlingStrategy":"validation","validationCode":"const mode = process.argv[2];\nif (!['--plan', '--check', '--apply'].includes(mode)) {\n  console.error('usage: node scripts/cloudflare-agent-readiness.mjs <--plan|--check|--apply>');\n  process.exit(2);\n}\nrunAgentReadiness(mode);","typeGuard":"function isValidMode(mode) {\n  return mode === '--plan' || mode === '--check' || mode === '--apply';\n}","tryCatchPattern":"try {\n  await runAgentReadiness(mode);\n} catch (e) {\n  if (e.message === 'Use --plan, --check, or --apply') {\n    console.error('usage: cloudflare-agent-readiness <--plan|--check|--apply>');\n    process.exit(2);\n  }\n  throw e;\n}","preventionTips":["Wrap the script in an npm script exposing only the three valid invocations.","Use shell completion or a Makefile target to avoid flag typos.","Validate argv.length before calling the exported function."],"tags":["cli","cloudflare","argument-validation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"7d06c8633d256c18e38133030bc3613976a96ec9","analyzedAt":"2026-09-15T16:44:39.439Z","contentChangedAt":"2026-09-15T16:44:39.439Z","schemaVersion":2},"datasetVersion":"2026-09-15T18:17:12.389Z"}