farion1231/cc-switch · error · PiFormValidationError

{{label}} must be a number greater than 0

Error message

{{label}} must be a number greater than 0

What it means

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 }).

Source

Thrown at src/components/providers/forms/PiProviderForm.tsx:241

  let parsed: URL;
  try {
    parsed = new URL(value);
  } catch {
    throw new Error(errorMessage);
  }
  if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
    throw new Error(errorMessage);
  }
}

function positiveNumber(
  value: string,
  errorMessage: string,
  fieldSelector: string,
): number {
  const parsed = Number(value);
  if (value.trim() === "" || !Number.isFinite(parsed) || parsed <= 0) {
    throw new PiFormValidationError(errorMessage, fieldSelector, true);
  }
  return parsed;
}

function supportsImageInput(value: unknown): boolean {
  return Array.isArray(value) && value.includes("image");
}

function withImageInput(value: unknown, enabled: boolean): string[] {
  const additionalInputTypes = Array.isArray(value)
    ? value.filter(
        (item): item is string =>
          typeof item === "string" && item !== "text" && item !== "image",
      )
    : [];
  return [
    "text",
    ...(enabled ? ["image"] : []),

View on GitHub (pinned to 0b5da51016)

Solutions

  1. Enter a plain positive number (e.g. 200000) for contextWindow / maxTokens
  2. Leave the field empty and untick the include toggle so the key is omitted instead of validated
  3. Constrain the input with type=number min=1 and strip thousands separators on paste

Example fix

// before (model form state)
contextWindow: '0'

// after (model form state)
contextWindow: '200000'
Defensive patterns

Strategy: validation

Validate before calling

function isPositiveNumberInput(value: string): boolean {
  if (value.trim() === '') return false;
  const n = Number(value);
  return Number.isFinite(n) && n > 0;
}
for (const field of includedNumericFields) {
  if (!isPositiveNumberInput(field.value)) {
    // mark the advanced field before submit
  }
}

Try / catch

try {
  buildProviderConfig(form);
} catch (error) {
  if (error instanceof PiFormValidationError && error.revealAdvanced) {
    // numeric field failure: expand advanced section and focus error.fieldSelector
    focusField(error.fieldSelector, true);
    showFormError(error.message);
  } else {
    throw error;
  }
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of farion1231/cc-switch@0b5da51016 (2026-08-20). Data as JSON: /api/errors/fcbe429972de2c2b. Report an issue: GitHub.