farion1231/cc-switch · warning · PiFormValidationError
pi.form.providerKeyRequired
Error message
pi.form.providerKeyRequired
What it means
Thrown by PiProviderForm's submit() in create mode only (!isEdit) when providerKey.trim() is empty (PiProviderForm.tsx:1084-1088). providerKey is the provider's config slug in Pi's settings and is live-normalized by handleProviderKeyChange (PiProviderForm.tsx:1063-1066): lowercased with everything outside [a-z0-9-] stripped. fieldSelector is '#pi-provider-key', so the form focuses that field. In edit mode the check is skipped because the immutable providerId is reused.
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 a2e22f3302)
Solutions
- Type a key using lowercase letters, digits, and hyphens (normalization applies live, watch the field reflect it)
- Pre-fill the key from the display name (slugified) when the user leaves it blank
- Disable Save in create mode when the normalized key is empty
Example fix
// before
const trimmedKey = providerKey.trim();
if (!isEdit && !trimmedKey) throw new PiFormValidationError(t("pi.form.providerKeyRequired"), "#pi-provider-key");
// after (derive a slug when the user left it blank)
const slug = (s: string) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
const trimmedKey = providerKey.trim() || slug(identity.name); Defensive patterns
Strategy: validation
Validate before calling
const normalizedKey = identity.providerKey.toLowerCase().replace(/[^a-z0-9-]/g, "");
if (!isEdit && normalizedKey === "") {
setFormError(t("pi.form.providerKeyRequired"));
return;
} Try / catch
try {
await submit(identity);
} catch (error) {
if (error instanceof Error && error.name === "PiFormValidationError") { /* focus '#pi-provider-key' */ return; }
throw error;
} Prevention
- Mirror the live normalization (lowercase, [a-z0-9-] only) in your UI hint so users see the final key
- Auto-derive a slug from the display name when the key is left blank
- Disable Save in create mode while the normalized key is empty
When it happens
Trigger: Creating a provider and leaving the key field empty, or typing characters that all get stripped by the normalizer (e.g. only uppercase CJK text, emojis, underscores, or dots), leaving the normalized value empty.
Common situations: Users typing 'My_Key' expect 'my_key' but get 'mykey'; users typing non-Latin-only content end up with an empty key; paste of a name with only symbols/whitespace.
Related errors
- pi.form.selectPresetRequired
- jsonEditor.mustBeObject
- pi.form.nameRequired
- pi.form.credentialRequired
- pi.form.modelRequired
AI-assisted analysis of farion1231/cc-switch@a2e22f3302 (2026-08-16).
Data as JSON: /api/errors/e9aede78309780b7.
Report an issue: GitHub.