farion1231/cc-switch · warning · PiFormValidationError

pi.form.modelRequired

Error message

pi.form.modelRequired

What it means

Thrown by PiProviderForm's submit() in create mode when the models list is empty (PiProviderForm.tsx:1095-1101). A new Pi provider must declare at least one model entry; edit mode is exempt so an existing provider's models can be managed elsewhere. The error targets '#pi-add-model' with revealAdvanced=true, expanding the models section and focusing the add-model control.

Source

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

        throw new PiFormValidationError(
          t("pi.form.nameRequired"),
          'input[name="name"]',
        );
      }
      if (!isEdit && !trimmedKey) {
        throw new PiFormValidationError(
          t("pi.form.providerKeyRequired"),
          "#pi-provider-key",
        );
      }
      if (!isEdit && selectedPreset && apiKey.length === 0) {
        throw new PiFormValidationError(
          t("pi.form.credentialRequired"),
          "#pi-api-key",
        );
      }
      if (!isEdit && models.length === 0) {
        throw new PiFormValidationError(
          t("pi.form.modelRequired"),
          "#pi-add-model",
          true,
        );
      }

      const headers = normalizeRequestHeaders(providerHeaders);
      const seen = new Set<string>();
      const normalizedModels = models.map((model, index) => {
        // Pi treats model IDs as opaque strings. Trimming would rename an
        // imported model.
        const id = model.id;
        if (id.length === 0) {
          throw new PiFormValidationError(
            t("pi.form.modelIdRequired", { index: index + 1 }),
            `#pi-model-id-${model.key}`,
            true,
          );

View on GitHub (pinned to a2e22f3302)

Solutions

  1. Add at least one model row (ID plus display name) before saving
  2. Re-select the preset so its template models are re-applied
  3. When seeding from an import, default one model entry from the endpoint's known model list

Example fix

// before
const models: PiModelDraft[] = [];
await submit(identity);

// after (seed one row when creating)
const models = isEdit ? [] : [{ key: crypto.randomUUID(), id: 'my-model', name: 'Default', /* ... */ }];
Defensive patterns

Strategy: validation

Validate before calling

if (!isEdit && models.length === 0) {
  setFormError(t("pi.form.modelRequired"));
  return;
}

Try / catch

try {
  await submit(identity);
} catch (error) {
  if (error instanceof Error && error.name === "PiFormValidationError") { /* expands models section, focuses '#pi-add-model' */ return; }
  throw error;
}

Prevention

When it happens

Trigger: Creating a provider, removing every auto-filled model row (or picking a preset/template that ships no models), then saving; programmatic submission before any model rows are added.

Common situations: User deletes the prefilled model row intending to add 'the real one' later; custom preset selection leaves models empty; JSON import path that produced zero models.

Related errors


AI-assisted analysis of farion1231/cc-switch@a2e22f3302 (2026-08-16). Data as JSON: /api/errors/e3122fcb1c2719f9. Report an issue: GitHub.