DayuanJiang/next-ai-draw-io · warning · Error
Invalid preset name
Error message
Invalid preset name
What it means
The IPC handler config:save-preset requires preset.name to be a non-empty trimmed string before sanitizing and persisting the config.
Source
Thrown at electron/main/ipc-handlers.ts:160
ipcMain.handle("config-presets:get-current", () => {
return getCurrentPreset()
})
ipcMain.handle("config-presets:get-current-id", () => {
return getCurrentPresetId()
})
ipcMain.handle(
"config-presets:save",
(
_event,
preset: Omit<ConfigPreset, "id" | "createdAt" | "updatedAt"> & {
id?: string
},
) => {
// Validate preset name
if (typeof preset.name !== "string" || !preset.name.trim()) {
throw new Error("Invalid preset name")
}
// Sanitize config to only allow whitelisted keys
const sanitizedConfig = sanitizePresetConfig(preset.config ?? {})
if (preset.id) {
// Update existing preset
return updatePreset(preset.id, {
name: preset.name.trim(),
config: sanitizedConfig,
})
}
// Create new preset
return createPreset({
name: preset.name.trim(),
config: sanitizedConfig,
})
},View on GitHub (pinned to 155ef4f7ac)
Solutions
- Ensure the save form validates name before calling the IPC
- Pass preset.name as a non-empty trimmed string
- Add a required-field check in the UI so users can't submit blank names
Example fix
// before
await ipcRenderer.invoke('config:save-preset', { name: '', config })
// after
const name = nameInput.trim()
if (!name) throw new Error('Preset name is required')
await ipcRenderer.invoke('config:save-preset', { name, config }) Defensive patterns
Strategy: validation
Validate before calling
const isValidPreset = (p: { name?: unknown }) =>
typeof p?.name === 'string' && p.name.trim().length > 0 Type guard
const hasValidPresetName = (p: unknown): p is { name: string } =>
typeof (p as any)?.name === 'string' && (p as any).name.trim() !== '' Try / catch
try { await ipcRenderer.invoke('config:save-preset', preset) } catch (e) { showFieldError('name', (e as Error).message) } Prevention
- Require the name input in the preset form before enabling save
- Trim and validate preset shape in the renderer before IPC
- Test the IPC boundary with empty-name payloads
When it happens
Trigger: Renderer sends config:save-preset with preset.name = '', whitespace-only, undefined, or a non-string value (e.g. number).
Common situations: Form state where the name input was never filled, or a refactor that renamed the field (label vs name).
Related errors
- ModelScope API error (${response.status}): ${errorText}
- Unexpected response format: ${contentType}
- Failed to encrypt API key. Cannot securely store credentials
- Server startup timeout after ${timeout}ms
- Server script not found at ${serverPath}. Please ensure the
AI-assisted analysis of DayuanJiang/next-ai-draw-io@155ef4f7ac (2026-08-27).
Data as JSON: /api/errors/19671ad0f940f477.
Report an issue: GitHub.