{"record":{"id":"2cd2f27d097e973c","repo":"mastra-ai/mastra","slug":"name-must-be-an-integer-range-received-js","errorCode":null,"errorMessage":"${name} must be an integer ${range}; received ${JSON.stringify(raw)}.","messagePattern":"(.+?) must be an integer (.+?); received (.+?)\\.","errorType":"validation","errorClass":"ProcessMemoryDiagnosticsConfigError","httpStatus":null,"severity":"warning","filePath":"mastracode/sdk/src/process-memory-diagnostics.ts","lineNumber":116,"sourceCode":"}\n\nfunction isEnabled(value: string | undefined): boolean {\n  return ['1', 'true', 'yes', 'on'].includes(value?.trim().toLowerCase() ?? '');\n}\n\nfunction parseBoundedInteger(\n  env: ProcessMemoryDiagnosticsEnvironment,\n  name: keyof ProcessMemoryDiagnosticsEnvironment,\n  fallback: number,\n  minimum: number,\n  maximum?: number,\n): number {\n  const raw = env[name];\n  if (raw === undefined || raw.trim() === '') return fallback;\n  const value = Number(raw);\n  if (!Number.isSafeInteger(value) || value < minimum || (maximum !== undefined && value > maximum)) {\n    const range = maximum === undefined ? `greater than or equal to ${minimum}` : `between ${minimum} and ${maximum}`;\n    throw new ProcessMemoryDiagnosticsConfigError(\n      `${name} must be an integer ${range}; received ${JSON.stringify(raw)}.`,\n    );\n  }\n  return value;\n}\n\nfunction getDefaultProfileParentDirectory(): string {\n  if (process.env.MASTRA_APP_DATA_DIR) return join(process.env.MASTRA_APP_DATA_DIR, 'profiles');\n\n  const baseDirectory =\n    platform === 'darwin'\n      ? join(homedir(), 'Library', 'Application Support')\n      : platform === 'win32'\n        ? process.env.APPDATA || join(homedir(), 'AppData', 'Roaming')\n        : process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share');\n  return join(baseDirectory, 'mastracode', 'profiles');\n}\n","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/sdk/src/process-memory-diagnostics.ts#L98-L134","documentation":"ProcessMemoryDiagnosticsConfigError thrown by parseBoundedInteger when a MASTRACODE_PROFILE_* environment variable is set but is not a valid safe integer within the allowed range (minimum from PROCESS_MEMORY_DIAGNOSTICS_MINIMUMS, maximum of 2147483647 for interval values). The library validates env-supplied tuning values instead of silently clamping them, so a bad value aborts configuration. The message names the variable, the expected range, and the raw value received.","triggerScenarios":"Setting MASTRACODE_PROFILE_SAMPLE_INTERVAL_MS, MASTRACODE_PROFILE_CAPTURE_INTERVAL_MS, or MASTRACODE_PROFILE_ALLOCATION_INTERVAL_BYTES to a non-numeric string (e.g. '10s'), a non-integer ('0.5'), a value below its minimum (sample<1000, capture<10000, allocation<32768), or an interval above 2147483647; also an empty-ish non-blank string like ' '.","commonSituations":"Copy-pasting durations with units ('500ms'), using seconds instead of milliseconds ('10' intending 10s but minimum is 1000ms — actually valid, but '5' fails), typos, or CI env injection with quoted values like '\"10000\"'.","solutions":["Correct the env variable to a plain integer string within range, e.g. MASTRACODE_PROFILE_SAMPLE_INTERVAL_MS=10000","Remove the variable to fall back to the defaults (sample 10000ms, capture 300000ms, allocation 524288 bytes)","Check the message for the exact allowed range: intervals must be 1..2147483647 (sample), 10000..2147483647 (capture), allocation >=32768"],"exampleFix":"// before\nMASTRACODE_PROFILE_SAMPLE_INTERVAL_MS=10s\n// after\nMASTRACODE_PROFILE_SAMPLE_INTERVAL_MS=10000","handlingStrategy":"validation","validationCode":"function validateProfileEnv(env: NodeJS.ProcessEnv = process.env): string[] {\n  const issues: string[] = [];\n  const check = (name: string, min: number) => {\n    const raw = env[name];\n    if (raw === undefined || raw.trim() === '') return;\n    const v = Number(raw);\n    if (!Number.isSafeInteger(v) || v < min) issues.push(`${name} must be an integer >= ${min}, got ${raw}`);\n  };\n  check('MASTRACODE_PROFILE_SAMPLE_INTERVAL_MS', 1000);\n  check('MASTRACODE_PROFILE_CAPTURE_INTERVAL_MS', 10000);\n  check('MASTRACODE_PROFILE_ALLOCATION_INTERVAL_BYTES', 32768);\n  return issues;\n}","typeGuard":"function isValidProfileInt(raw: string | undefined, min: number): raw is string {\n  if (raw === undefined) return true;\n  const v = Number(raw);\n  return Number.isSafeInteger(v) && v >= min;\n}","tryCatchPattern":"try {\n  const setup = createProcessMemoryDiagnosticsFromEnvironment(env);\n} catch (error) {\n  if (error instanceof ProcessMemoryDiagnosticsConfigError) {\n    console.error(`Bad profiling config: ${error.message}`);\n  } else throw error;\n}","preventionTips":["Use plain integer strings (milliseconds/bytes) with no units or quotes in env config","Call parseProcessMemoryDiagnosticsEnvironment() early at startup to fail fast before heavy work","Remember the minimums: sample >=1000ms, capture >=10000ms, allocation >=32768 bytes"],"tags":["configuration","env-vars","validation"],"backgroundTag":"invalid-env-var-value","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}