{"record":{"id":"9eaebafe2357c07a","repo":"DayuanJiang/next-ai-draw-io","slug":"varname-must-be-min-got-parsed","errorCode":null,"errorMessage":"${varName} must be >= ${min}, got: ${parsed}","messagePattern":"(.+?) must be >= (.+?), got: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/ai-providers.ts","lineNumber":232,"sourceCode":"    return process.env[defaultEnvVar]\n}\n\n/**\n * Safely parse integer from environment variable with validation\n */\nfunction parseIntSafe(\n    value: string | undefined,\n    varName: string,\n    min?: number,\n    max?: number,\n): number | undefined {\n    if (!value) return undefined\n    const parsed = Number.parseInt(value, 10)\n    if (Number.isNaN(parsed)) {\n        throw new Error(`${varName} must be a valid integer, got: ${value}`)\n    }\n    if (min !== undefined && parsed < min) {\n        throw new Error(`${varName} must be >= ${min}, got: ${parsed}`)\n    }\n    if (max !== undefined && parsed > max) {\n        throw new Error(`${varName} must be <= ${max}, got: ${parsed}`)\n    }\n    return parsed\n}\n\n/**\n * Build provider-specific options from environment variables\n * Supports various AI SDK providers with their unique configuration options\n *\n * Environment variables:\n * - OPENAI_REASONING_EFFORT: OpenAI reasoning effort level (minimal/low/medium/high) - for o1/o3/o4/gpt-5\n * - OPENAI_REASONING_SUMMARY: OpenAI reasoning summary (auto/detailed) - auto-enabled for o1/o3/o4/gpt-5\n * - ANTHROPIC_THINKING_BUDGET_TOKENS: Anthropic thinking budget in tokens (1024-64000)\n * - ANTHROPIC_THINKING_TYPE: Anthropic thinking type (enabled)\n * - GOOGLE_THINKING_BUDGET: Google Gemini 2.5 thinking budget in tokens (1024-100000)\n * - GOOGLE_THINKING_LEVEL: Google Gemini 3 thinking level (low/high)","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/DayuanJiang/next-ai-draw-io/blob/155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1/lib/ai-providers.ts#L214-L250","documentation":"parseIntSafe enforces an optional lower bound; when the parsed integer is below min (e.g. 0 or negative for a count), it throws naming the variable and minimum.","triggerScenarios":"Setting e.g. GOOGLE_TOP_K=0, CANDIDATE_COUNT=-1, or a negative thinking budget where the option requires >= 1.","commonSituations":"Attempting to disable an option by setting 0, or sign typos/negative values copied from examples.","solutions":["Set the value to at least the documented minimum (usually 1)","Remove the env var entirely to disable the option rather than using 0","Double-check for accidental minus signs"],"exampleFix":"# before\nGOOGLE_TOP_K=0\n\n# after\nGOOGLE_TOP_K=1  # or remove the variable entirely","handlingStrategy":"validation","validationCode":"const inRange = (v: string, min?: number, max?: number) => {\n  const n = Number.parseInt(v, 10)\n  return !Number.isNaN(n) && (min === undefined || n >= min) && (max === undefined || n <= max)\n}","typeGuard":"const isNonNegativeInt = (v: string): boolean => /^\\d+$/.test(v) && Number.parseInt(v, 10) >= 0","tryCatchPattern":"try { ... } catch (e) { if ((e as Error).message.includes('must be >=')) clampOrRemoveEnvVar(e) }","preventionTips":["Use >=1 for counts/topK; omit env var to disable rather than 0","Validate env at startup with a schema (zod)"],"tags":["env-var","validation","range","configuration"],"backgroundTag":"invalid-env-var-value","analyzedSha":"155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1","analyzedAt":"2026-08-27T11:40:38.297Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}