{"record":{"id":"fcbe429972de2c2b","repo":"farion1231/cc-switch","slug":"label-must-be-a-number-greater-than-0","errorCode":null,"errorMessage":"{{label}} must be a number greater than 0","messagePattern":"(.+?)\\} must be a number greater than 0","errorType":"validation","errorClass":"PiFormValidationError","httpStatus":null,"severity":"error","filePath":"src/components/providers/forms/PiProviderForm.tsx","lineNumber":241,"sourceCode":"  let parsed: URL;\n  try {\n    parsed = new URL(value);\n  } catch {\n    throw new Error(errorMessage);\n  }\n  if (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\") {\n    throw new Error(errorMessage);\n  }\n}\n\nfunction positiveNumber(\n  value: string,\n  errorMessage: string,\n  fieldSelector: string,\n): number {\n  const parsed = Number(value);\n  if (value.trim() === \"\" || !Number.isFinite(parsed) || parsed <= 0) {\n    throw new PiFormValidationError(errorMessage, fieldSelector, true);\n  }\n  return parsed;\n}\n\nfunction supportsImageInput(value: unknown): boolean {\n  return Array.isArray(value) && value.includes(\"image\");\n}\n\nfunction withImageInput(value: unknown, enabled: boolean): string[] {\n  const additionalInputTypes = Array.isArray(value)\n    ? value.filter(\n        (item): item is string =>\n          typeof item === \"string\" && item !== \"text\" && item !== \"image\",\n      )\n    : [];\n  return [\n    \"text\",\n    ...(enabled ? [\"image\"] : []),","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/farion1231/cc-switch/blob/0b5da510168914b251481654a568c3ffacd62cf4/src/components/providers/forms/PiProviderForm.tsx#L223-L259","documentation":"positiveNumber is the Pi form's guard for numeric model fields: Number(value) must be finite and > 0, and blank strings fail too. On failure it throws PiFormValidationError directly (not via validatePiField) with revealAdvanced = true, so the form expands the advanced section and focuses the field. Call sites are contextWindow ('#pi-model-context-window-<key>') and maxTokens ('#pi-model-max-tokens-<key>'), with the message built from t('pi.form.positiveNumberRequired', { label }).","triggerScenarios":"Building the Pi provider config with includeContextWindow/includeMaxTokens enabled while the corresponding field is blank, 'abc', '0', '-5', or '1e999' (parses to Infinity, which is not finite).","commonSituations":"Optional-looking advanced fields left at 0 or filled by an import that produced strings; users entering human units like '8k'; locales using comma decimal separators.","solutions":["Enter a plain positive number (e.g. 200000) for contextWindow / maxTokens","Leave the field empty and untick the include toggle so the key is omitted instead of validated","Constrain the input with type=number min=1 and strip thousands separators on paste"],"exampleFix":"// before (model form state)\ncontextWindow: '0'\n\n// after (model form state)\ncontextWindow: '200000'","handlingStrategy":"validation","validationCode":"function isPositiveNumberInput(value: string): boolean {\n  if (value.trim() === '') return false;\n  const n = Number(value);\n  return Number.isFinite(n) && n > 0;\n}\nfor (const field of includedNumericFields) {\n  if (!isPositiveNumberInput(field.value)) {\n    // mark the advanced field before submit\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  buildProviderConfig(form);\n} catch (error) {\n  if (error instanceof PiFormValidationError && error.revealAdvanced) {\n    // numeric field failure: expand advanced section and focus error.fieldSelector\n    focusField(error.fieldSelector, true);\n    showFormError(error.message);\n  } else {\n    throw error;\n  }\n}","preventionTips":["Use type=number min=1 inputs for contextWindow/maxTokens","Untick the include toggle instead of entering 0 for unused numeric fields","Reject human units ('8k') and comma decimals on input"],"tags":["pi","form-validation","number","advanced-fields"],"backgroundTag":"positive-number-required","analyzedSha":"0b5da510168914b251481654a568c3ffacd62cf4","analyzedAt":"2026-08-20T14:29:00.113Z","contentChangedAt":"2026-08-20T14:29:00.113Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}