farion1231/cc-switch · warning · PiFormValidationError

Provider key is required

Error message

Provider key is required

What it means

In create mode, PiProviderForm requires a provider key: submit() trims providerKey and throws pi.form.providerKeyRequired (focusing #pi-provider-key) when it is empty. Note handleProviderKeyChange normalizes every keystroke with value.toLowerCase().replace(/[^a-z0-9-]/g, ""), so a key made entirely of disallowed characters (spaces, underscores, CJK, emoji) is coerced to the empty string and trips this error even though the user typed something.

Source

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

      if (!isEdit && selectedPresetId === null) {
        throw new PiFormValidationError(t("pi.form.selectPresetRequired"));
      }
      if (!parseJsonObject(identity.settingsConfig)) {
        throw new PiFormValidationError(
          t("jsonEditor.mustBeObject"),
          "#pi-settings-config",
        );
      }
      const trimmedName = identity.name.trim();
      const trimmedKey = providerKey.trim();
      if (!trimmedName) {
        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,
        );
      }

View on GitHub (pinned to 0b5da51016)

Solutions

  1. Enter a provider key using only lowercase letters, digits, and hyphens (e.g. "my-pi-provider").
  2. If your typed input keeps disappearing, check for characters outside [a-z0-9-] — switch the IME to half-width ASCII input.
  3. Convert offending separators yourself before typing: replace spaces with hyphens rather than relying on deletion.

Example fix

// before
handleProviderKeyChange("My Provider_"); // stored as "myprovider" ok
handleProviderKeyChange("配置"); // normalizes to "" -> throws on submit

// after
handleProviderKeyChange("custom-provider-1"); // passes [a-z0-9-] filter unchanged
Defensive patterns

Strategy: validation

Validate before calling

const normalizeKey = (v: string) => v.toLowerCase().replace(/[^a-z0-9-]/g, "");
const keyOk = isEdit || normalizeKey(providerKey).length > 0;
if (!keyOk) warnUser("Provider key needs a-z, 0-9 or - characters");

Try / catch

catch (e) {
  if (e instanceof PiFormValidationError && e.fieldSelector === "#pi-provider-key") { showHint("Use lowercase letters, digits, hyphens"); return; }
  throw e;
}

Prevention

When it happens

Trigger: Submitting the create form with the provider key blank; typing a key like "my key" is fine (becomes "mykey"), but typing "我的" or "###" normalizes to "" and throws. Editing an existing provider never throws this (guarded by !isEdit).

Common situations: Users paste a provider title with only non-ASCII characters; an IME composition inserts characters that are all stripped; the key input was cleared by the normalizer after paste.

Related errors


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