{"record":{"id":"377e1acc9c85ecf7","repo":"pydantic/monty","slug":"invalid-printflushinterval-expected-a-non-negative-number-of","errorCode":null,"errorMessage":"invalid printFlushInterval: expected a non-negative number of seconds, got ${interval}","messagePattern":"invalid printFlushInterval: expected a non-negative number of seconds, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"crates/monty-js/ts/worker/transport.ts","lineNumber":40,"sourceCode":"  Value as ComponentValue,\n} from './component/monty.component.js'\nimport type { Dispatcher } from './host.js'\nimport { decodeValue, encodeValue } from './value.js'\n\ntype OnPrint = (stream: 'stdout' | 'stderr', text: string) => void\n\n/**\n * Encodes a print flush interval (seconds) as whole milliseconds for the WIT\n * `u32`, mirroring `monty-pool`'s `flush_interval_ms`.\n *\n * The component encodes a `u32` as `val >>> 0`, which would silently wrap a\n * negative or non-finite value into a huge interval, so reject those here.\n * Zero is the line-buffering sentinel, so a positive interval never rounds\n * down into it.\n */\nfunction flushIntervalMs(interval: number): number {\n  if (!Number.isFinite(interval) || interval < 0) {\n    throw new TypeError(`invalid printFlushInterval: expected a non-negative number of seconds, got ${interval}`)\n  }\n  return interval === 0 ? 0 : Math.min(Math.max(Math.floor(interval * 1000), 1), 0xffffffff)\n}\n\n/** Resource limits mirrored from the napi pool; the transport enforces `maxSuspensions`. */\nexport interface ResourceLimits {\n  maxDurationSecs?: number\n  maxMemory?: number\n  gcInterval?: number\n  maxRecursionDepth?: number\n  maxSuspensions?: number\n}\n\n/** Session-creation options sent to the component worker. */\nexport interface WorkerSessionConfig {\n  scriptName?: string\n  limits?: ResourceLimits\n  typeCheck?: boolean","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-js/ts/worker/transport.ts#L22-L58","documentation":"`printFlushInterval` is given in seconds and is converted to a millisecond flush interval for the worker's print buffering. A non-finite (NaN/Infinity) or negative value cannot be turned into a valid timer interval, so the transport rejects it with a `TypeError` before creating the session. Zero is allowed and means line-buffered (unbuffered) flushing.","triggerScenarios":"Passing `printFlushInterval: NaN`, `Infinity`, `-1`, or any non-finite/negative number in the `WorkerSessionConfig` handed to `pool.checkout()` or `WorkerTransport.create()`.","commonSituations":"Computing the interval from a config parse that produced NaN (e.g. `Number(undefined)`), unit confusion (writing a negative 'disable' sentinel), or copying a config from another library that uses `Infinity` to mean 'never flush'.","solutions":["Pass a finite, non-negative number of seconds (e.g. `0.05` for 50ms) or `0` for line-buffered behavior.","Clamp/validate the value before constructing the config: `const interval = Number.isFinite(v) && v >= 0 ? v : 0.05`.","If the value comes from user config, sanitize at load time so NaN/negatives become the documented default instead of reaching checkout().","Omit `printFlushInterval` entirely to use the library default when you don't need custom flushing."],"exampleFix":"// before\nconst session = await pool.checkout({ printFlushInterval: Number(process.env.FLUSH_S) }) // NaN if unset\n\n// after\nconst raw = Number(process.env.FLUSH_S)\nconst printFlushInterval = Number.isFinite(raw) && raw >= 0 ? raw : 0.05\nconst session = await pool.checkout({ printFlushInterval })","handlingStrategy":"validation","validationCode":"function sanitizeInterval(v: unknown): number {\n  const n = Number(v)\n  return Number.isFinite(n) && n >= 0 ? n : 0\n}","typeGuard":"function isFlushInterval(v: unknown): v is number {\n  return typeof v === 'number' && Number.isFinite(v) && v >= 0\n}","tryCatchPattern":"try {\n  session = await pool.checkout({ printFlushInterval: raw })\n} catch (err) {\n  if (err instanceof TypeError && err.message.includes('printFlushInterval')) {\n    session = await pool.checkout({ printFlushInterval: 0.05 })\n  } else throw err\n}","preventionTips":["Sanitize env/config numbers with Number.isFinite before use.","Remember 0 means line-buffered, not 'disabled'.","Express the value in seconds, not milliseconds.","Validate all WorkerSessionConfig fields at config-load time."],"tags":["config","validation","typescript","wasm-worker"],"backgroundTag":"invalid-config-value","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}