farion1231/cc-switch · warning · PiFormValidationError
pi.form.nameRequired
Error message
pi.form.nameRequired
What it means
Thrown by PiProviderForm's submit() when identity.name.trim() is empty (PiProviderForm.tsx:1075-1082). The provider display name is mandatory in both create and edit mode; whitespace-only names are rejected because the check runs on the trimmed value. fieldSelector is 'input[name="name"]', so the form focuses the name input after surfacing the inline error and toast.
Source
Thrown at src/components/providers/forms/PiProviderForm.tsx:1079
}, []);
const submit = async (identity: ProviderFormData) => {
onSubmittingChange?.(true);
setFormError(null);
try {
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(View on GitHub (pinned to a2e22f3302)
Solutions
- Enter a non-blank display name and save again
- Trim client input and disable Save when name.trim() === ''
- If names should auto-derive, default them from the selected preset's label before submit
Example fix
// before
const values = { name: identity.name, ... };
// after
const values = { name: identity.name.trim(), ... };
// and disable submit when identity.name.trim() === '' Defensive patterns
Strategy: validation
Validate before calling
const trimmedName = identity.name.trim();
if (trimmedName === "") {
setFormError(t("pi.form.nameRequired"));
return;
} Try / catch
try {
await submit(identity);
} catch (error) {
if (error instanceof Error && error.name === "PiFormValidationError") { /* inline error, focus name input */ return; }
throw error;
} Prevention
- Disable Save while the trimmed name is empty
- Trim on change, not only on submit, so whitespace-only input is visible
- Pre-fill the name from the selected preset label in create mode
When it happens
Trigger: Submitting with an empty Name field, or a name consisting only of spaces/tabs/newlines; programmatic submissions that never set identity.name.
Common situations: User tabs past the name field assuming the preset fills it; pasting a name that is only whitespace; edit flows that clear the name but keep other fields.
Related errors
- pi.form.modelRequired
- pi.form.selectPresetRequired
- jsonEditor.mustBeObject
- pi.form.providerKeyRequired
- pi.form.credentialRequired
AI-assisted analysis of farion1231/cc-switch@a2e22f3302 (2026-08-16).
Data as JSON: /api/errors/c03d05a1019d643b.
Report an issue: GitHub.