{"record":{"id":"5e826ed13c02b558","repo":"affaan-m/ECC","slug":"replay-bad-mode","errorCode":"replay.bad_mode","errorMessage":"mode must be record or replay, got ${mode}","messagePattern":"mode must be record or replay, got (.+?)","errorType":"error_code","errorClass":"ReplayError","httpStatus":null,"severity":"error","filePath":"scripts/lib/eval-harness/replay.js","lineNumber":95,"sourceCode":"      throw new ReplayError('tool.fixture_mismatch', `fixture ${key.slice(0, 16)} was recorded for different arguments`, { tool, key });\n    }\n    if (record.response_hash !== hashValue(record.response)) {\n      throw new ReplayError('tool.fixture_mismatch', `fixture ${key.slice(0, 16)} response hash does not match its content`, { tool, key });\n    }\n    return record;\n  }\n}\n\n/**\n * tools: { name: { effect_class, determinism: 'deterministic'|'nondeterministic', impl(args) } }\n * options: { mode: 'record'|'replay', store: FixtureStore, maxEffectClass: 'SE2', onCall(entry) }\n */\nfunction createReplayer(tools, options = {}) {\n  const mode = options.mode || 'replay';\n  const store = options.store;\n  const maxRank = envelope.effectRank(options.maxEffectClass || 'SE2');\n  if (!['record', 'replay'].includes(mode)) {\n    throw new ReplayError('replay.bad_mode', `mode must be record or replay, got ${mode}`);\n  }\n  if (!store) {\n    throw new ReplayError('replay.no_store', 'a FixtureStore is required');\n  }\n  for (const [name, tool] of Object.entries(tools)) {\n    if (!envelope.EFFECT_CLASSES.includes(tool.effect_class)) {\n      throw new ReplayError('replay.bad_declaration', `tool ${name} must declare an effect_class`);\n    }\n    if (!['deterministic', 'nondeterministic'].includes(tool.determinism)) {\n      throw new ReplayError('replay.bad_declaration', `tool ${name} must declare determinism`);\n    }\n  }\n\n  const calls = [];\n  const emit = (entry) => {\n    calls.push(entry);\n    if (typeof options.onCall === 'function') {\n      options.onCall(entry);","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/eval-harness/replay.js#L77-L113","documentation":"createReplayer throws ReplayError('replay.bad_mode') when options.mode is neither 'record' nor 'replay' (the default is 'replay'). The replayer only supports these two modes because they define whether the live implementation may run. Failing fast at construction prevents silently running a suite in an unintended mode.","triggerScenarios":"Passing options.mode with a typo (e.g. 'Record', 'rec', 'capture'), reading the mode from an env var or CLI flag that is unset or misspelled (process.env.EVAL_MODE may be undefined-turned-string, empty string ''), or passing a non-string value.","commonSituations":"CI pipeline sets MODE=replay-vs-record style values; developers add a 'live' or 'passthrough' mode that the library does not support; a config file uses 'record-mode' naming; empty string env var overriding the default.","solutions":["Set mode to exactly 'record' or 'replay' (lowercase) in the createReplayer options.","If the mode comes from an env var/CLI flag, normalize and validate it before passing: const mode = process.env.EVAL_MODE === 'record' ? 'record' : 'replay'.","Omit the mode option entirely to use the safe default ('replay').","Check for empty-string env overrides — `EVAL_MODE= npm test` yields '' which fails this check; delete the var or default it."],"exampleFix":"// before\nconst replayer = createReplayer(tools, { mode: process.env.EVAL_MODE, store });\n\n// after\nconst mode = process.env.EVAL_MODE === 'record' ? 'record' : 'replay';\nconst replayer = createReplayer(tools, { mode, store });","handlingStrategy":"validation","validationCode":"const MODES = ['record', 'replay'];\nconst mode = MODES.includes(process.env.EVAL_MODE) ? process.env.EVAL_MODE : 'replay';","typeGuard":"function isReplayMode(v) {\n  return v === 'record' || v === 'replay';\n}","tryCatchPattern":"try {\n  return createReplayer(tools, { mode, store });\n} catch (e) {\n  if (e instanceof ReplayError && e.code === 'replay.bad_mode') {\n    throw new Error(`EVAL_MODE must be 'record' or 'replay', received: ${JSON.stringify(mode)}`);\n  }\n  throw e;\n}","preventionTips":["Normalize env/CLI mode input against a whitelist before constructing the replayer","Default to 'replay' (the safe mode) whenever the input is unrecognized","Watch for empty-string env vars overriding defaults","Centralize mode parsing in one helper instead of repeating it per suite"],"tags":["configuration","validation","enum","replay"],"backgroundTag":"invalid-enum-value","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}