diff --git a/desktop/src/components/HandParamsForm.tsx b/desktop/src/components/HandParamsForm.tsx index 796f1a5..e080999 100644 --- a/desktop/src/components/HandParamsForm.tsx +++ b/desktop/src/components/HandParamsForm.tsx @@ -31,6 +31,7 @@ import { Info, } from 'lucide-react'; import type { HandParameter } from '../types/hands'; +import { parseJsonOrDefault, safeJsonParse } from '../lib/json-utils'; // === Types === @@ -144,13 +145,9 @@ function getPresetStorageKey(handId: string): string { } function loadPresets(handId: string): ParameterPreset[] { - try { - const stored = localStorage.getItem(getPresetStorageKey(handId)); - if (stored) { - return JSON.parse(stored) as ParameterPreset[]; - } - } catch { - // Ignore parse errors + const stored = localStorage.getItem(getPresetStorageKey(handId)); + if (stored) { + return parseJsonOrDefault(stored, []); } return []; } @@ -405,15 +402,15 @@ function ObjectParamInput({ param, value, onChange, disabled, error }: ParamInpu return; } - try { - const parsed = JSON.parse(text); - if (typeof parsed === 'object' && !Array.isArray(parsed)) { - onChange(parsed); + const result = safeJsonParse(text); + if (result.success) { + if (typeof result.data === 'object' && !Array.isArray(result.data)) { + onChange(result.data as Record); setParseError(null); } else { setParseError('Value must be a JSON object'); } - } catch { + } else { setParseError('Invalid JSON format'); } }; diff --git a/desktop/src/components/RightPanel.tsx b/desktop/src/components/RightPanel.tsx index aaefbb9..225608a 100644 --- a/desktop/src/components/RightPanel.tsx +++ b/desktop/src/components/RightPanel.tsx @@ -574,6 +574,8 @@ export function RightPanel() { + + )} ); diff --git a/desktop/src/components/WorkflowEditor.tsx b/desktop/src/components/WorkflowEditor.tsx index 9c3f537..4a8fff2 100644 --- a/desktop/src/components/WorkflowEditor.tsx +++ b/desktop/src/components/WorkflowEditor.tsx @@ -23,6 +23,7 @@ import { AlertCircle, GitBranch, } from 'lucide-react'; +import { safeJsonParse } from '../lib/json-utils'; // === Types === @@ -163,11 +164,15 @@ function StepEditor({ step, hands, index, onUpdate, onRemove, onMoveUp, onMoveDo