{"record":{"id":"15bc103bd853ce90","repo":"mastra-ai/mastra","slug":"queuehealthstorage-thresholdsseconds-must-be-a-n","errorCode":null,"errorMessage":"[QueueHealthStorage] thresholdsSeconds must be a non-empty array of finite numbers.","messagePattern":"\\[QueueHealthStorage\\] thresholdsSeconds must be a non-empty array of finite numbers\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/storage/domains/queue-health/base.ts","lineNumber":35,"sourceCode":"export interface QueueHealthConfig {\n  /** Ordered-ascending age boundaries in seconds, e.g. `[14400, 86400, 259200]`. */\n  thresholdsSeconds: number[];\n}\n\n/** Default: green <4h, amber <24h, orange <72h, red 72h+. */\nexport const DEFAULT_QUEUE_HEALTH_CONFIG: QueueHealthConfig = {\n  thresholdsSeconds: [14400, 86400, 259200],\n};\n\n/**\n * Throw unless `thresholdsSeconds` is a non-empty ascending number list. A\n * descending config would silently invert bucket semantics, so validate at the\n * write boundary rather than trusting callers.\n */\nexport function assertValidThresholds(config: QueueHealthConfig): void {\n  const t = config.thresholdsSeconds;\n  if (!Array.isArray(t) || t.length === 0 || t.some(v => typeof v !== 'number' || !Number.isFinite(v))) {\n    throw new Error('[QueueHealthStorage] thresholdsSeconds must be a non-empty array of finite numbers.');\n  }\n  for (let i = 1; i < t.length; i++) {\n    if (t[i]! <= t[i - 1]!) {\n      throw new Error('[QueueHealthStorage] thresholdsSeconds must be strictly ascending.');\n    }\n  }\n}\n\n/** Validate untrusted JSON into a `QueueHealthConfig`, or `null` when invalid. */\nexport function parseQueueHealthConfig(body: unknown): QueueHealthConfig | null {\n  if (typeof body !== 'object' || body === null) return null;\n  const config = body as { thresholdsSeconds?: unknown };\n  if (!Array.isArray(config.thresholdsSeconds)) return null;\n  try {\n    assertValidThresholds(config as QueueHealthConfig);\n  } catch {\n    return null;\n  }","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/storage/domains/queue-health/base.ts#L17-L53","documentation":"assertValidThresholds validates QueueHealthConfig.thresholdsSeconds at the write boundary. It throws this error when the value is not an array, is empty, or contains any element that is not a finite number (NaN/Infinity included). Descending or duplicate thresholds have their own message.","triggerScenarios":"Calling saveConfig (or parseQueueHealthConfig) with thresholdsSeconds = [], undefined, a non-array, or an array containing NaN/Infinity/strings/nulls.","commonSituations":"Config loaded from a JSON file where the key was missing or the array was emptied by a filter; UI submitting an un-filled thresholds list; Infinity used as a sentinel upper bound.","solutions":["Provide a non-empty array of finite numbers for thresholdsSeconds","Replace Infinity/NaN sentinels with concrete numeric bounds","Guard the config file parsing so missing/empty thresholds are rejected before save","Use parseQueueHealthConfig to validate untrusted JSON before persisting"],"exampleFix":"// before\nawait storage.saveConfig({ thresholdsSeconds: [60, Infinity] });\n// after\nawait storage.saveConfig({ thresholdsSeconds: [60, 300, 900] });","handlingStrategy":"validation","validationCode":"function isValidThresholds(t: unknown): t is number[] {\n  return Array.isArray(t) && t.length > 0 && t.every(v => typeof v === 'number' && Number.isFinite(v));\n}\nif (!isValidThresholds(config.thresholdsSeconds)) throw new Error('thresholdsSeconds must be a non-empty finite number array');","typeGuard":"function isQueueHealthConfig(body: unknown): body is QueueHealthConfig {\n  const t = (body as QueueHealthConfig | undefined)?.thresholdsSeconds;\n  return isValidThresholds(t);\n}","tryCatchPattern":"try {\n  await storage.saveConfig(config);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('non-empty array of finite numbers')) {\n    throw new BadRequest('thresholdsSeconds is required as a non-empty list of finite numbers');\n  }\n  throw e;\n}","preventionTips":["Run untrusted JSON through parseQueueHealthConfig before saving","Reject NaN/Infinity sentinels in config validation","Give thresholds sane defaults instead of empty arrays","Type the config schema so empty arrays fail at build/parse time"],"tags":["validation","config","queue-health"],"backgroundTag":"schema-validation-failed","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}