{"record":{"id":"75d9573e3b80ca0a","repo":"stablyai/orca","slug":"name-must-be-positive-received-value","errorCode":null,"errorMessage":"${name} must be positive, received ${value}","messagePattern":"(.+?) must be positive, received (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"config/scripts/zustand-selector-fanout-benchmark.mjs","lineNumber":18,"sourceCode":"#!/usr/bin/env node\nimport { performance } from 'node:perf_hooks'\nimport process from 'node:process'\nimport { createStore } from 'zustand/vanilla'\n\nconst SUBSCRIBERS = Number.parseInt(process.env.ORCA_ZUSTAND_BENCH_SUBSCRIBERS ?? '2500', 10)\nconst WRITES = Number.parseInt(process.env.ORCA_ZUSTAND_BENCH_WRITES ?? '2000', 10)\nconst MAX_MILLISECONDS_PER_WRITE = Number.parseFloat(\n  process.env.ORCA_ZUSTAND_BENCH_MAX_MS_PER_WRITE ?? '5'\n)\n\nfor (const [name, value] of [\n  ['ORCA_ZUSTAND_BENCH_SUBSCRIBERS', SUBSCRIBERS],\n  ['ORCA_ZUSTAND_BENCH_WRITES', WRITES],\n  ['ORCA_ZUSTAND_BENCH_MAX_MS_PER_WRITE', MAX_MILLISECONDS_PER_WRITE]\n]) {\n  if (!Number.isFinite(value) || value <= 0) {\n    throw new Error(`${name} must be positive, received ${value}`)\n  }\n}\n\nfunction measureRound() {\n  const stableProjection = Object.freeze({ activeRepoId: 'repo-1' })\n  const store = createStore(() => ({ unrelatedWrite: 0, stableProjection }))\n  let selectorRuns = 0\n  let renderInvalidations = 0\n  const unsubscribe = Array.from({ length: SUBSCRIBERS }, () => {\n    let previous = store.getState().stableProjection\n    return store.subscribe((state) => {\n      selectorRuns += 1\n      const next = state.stableProjection\n      if (!Object.is(previous, next)) {\n        renderInvalidations += 1\n      }\n      previous = next\n    })","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/scripts/zustand-selector-fanout-benchmark.mjs#L1-L36","documentation":"Startup validation in the Zustand selector-fanout benchmark: it parses three env vars (ORCA_ZUSTAND_BENCH_SUBSCRIBERS, ORCA_ZUSTAND_BENCH_WRITES, ORCA_ZUSTAND_BENCH_MAX_MS_PER_WRITE) and throws if any is non-finite or <= 0. The benchmark needs positive counts/durations to produce meaningful throughput numbers.","triggerScenarios":"Setting any of the three env vars to 0, a negative number, NaN, Infinity, or a non-numeric string (parseInt/parseFloat yield NaN).","commonSituations":"Copy-pasting a partial env override (e.g. ORCA_ZUSTAND_BENCH_SUBSCRIBERS=0 to 'disable'), typos like `SUBSCRIBERS=-1`, or an unset var that the default fallback should have covered but a wrapper exported an empty string.","solutions":["Set all three env vars to positive finite numbers (e.g. SUBSCRIBERS=2500 WRITES=2000 MAX_MS_PER_WRITE=5).","Unset the vars to fall back to the documented defaults.","Check for an empty-string export (`export ORCA_ZUSTAND_BENCH_WRITES=`) which Number.parseInt('',10) turns into NaN."],"exampleFix":"// before\nif (!Number.isFinite(value) || value <= 0) {\n  throw new Error(`${name} must be positive, received ${value}`)\n}\n\n// after — allow empty/unset to fall back to default\nconst raw = process.env[name]\nif (raw !== undefined && raw !== '' && (!Number.isFinite(value) || value <= 0)) {\n  throw new Error(`${name} must be positive, received ${value}`)\n}","handlingStrategy":"validation","validationCode":"// Centralized env parser that treats empty/unset as default\nfunction positiveEnv(name: string, def: number): number {\n  const raw = process.env[name]\n  if (raw === undefined || raw === '') return def\n  const n = Number(raw)\n  if (!Number.isFinite(n) || n <= 0) {\n    throw new Error(`${name} must be positive, received ${raw}`)\n  }\n  return n\n}","typeGuard":"function isPositiveFinite(v: unknown): v is number {\n  return typeof v === 'number' && Number.isFinite(v) && v > 0\n}","tryCatchPattern":null,"preventionTips":["Document the three env vars and their defaults in the benchmark header.","Validate once at startup, not per round.","Print the resolved values when --verbose is set so misconfigurations are visible."],"tags":["benchmark","env-validation","zustand","config"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}