{"record":{"id":"ab73c1133106547a","repo":"farion1231/cc-switch","slug":"jsoneditor-mustbeobject","errorCode":null,"errorMessage":"jsonEditor.mustBeObject","messagePattern":"jsonEditor\\.mustBeObject","errorType":"validation","errorClass":"PiFormValidationError","httpStatus":null,"severity":"warning","filePath":"src/components/providers/forms/PiProviderForm.tsx","lineNumber":1071,"sourceCode":"      setProviderCompat(value);\n    },\n    [updateSettingsConfig],\n  );\n\n  const handleProviderKeyChange = useCallback((value: string) => {\n    const normalized = value.toLowerCase().replace(/[^a-z0-9-]/g, \"\");\n    setProviderKey(normalized);\n  }, []);\n\n  const submit = async (identity: ProviderFormData) => {\n    onSubmittingChange?.(true);\n    setFormError(null);\n    try {\n      if (!isEdit && selectedPresetId === null) {\n        throw new PiFormValidationError(t(\"pi.form.selectPresetRequired\"));\n      }\n      if (!parseJsonObject(identity.settingsConfig)) {\n        throw new PiFormValidationError(\n          t(\"jsonEditor.mustBeObject\"),\n          \"#pi-settings-config\",\n        );\n      }\n      const trimmedName = identity.name.trim();\n      const trimmedKey = providerKey.trim();\n      if (!trimmedName) {\n        throw new PiFormValidationError(\n          t(\"pi.form.nameRequired\"),\n          'input[name=\"name\"]',\n        );\n      }\n      if (!isEdit && !trimmedKey) {\n        throw new PiFormValidationError(\n          t(\"pi.form.providerKeyRequired\"),\n          \"#pi-provider-key\",\n        );\n      }","sourceCodeStart":1053,"sourceCodeEnd":1089,"githubUrl":"https://github.com/farion1231/cc-switch/blob/a2e22f330273a5b6ffa87cb8b82b624601bac562/src/components/providers/forms/PiProviderForm.tsx#L1053-L1089","documentation":"Thrown by PiProviderForm's submit() when identity.settingsConfig fails parseJsonObject() (PiProviderForm.tsx:157-166): the text must JSON.parse successfully AND the top-level value must be a non-null, non-array object. Arrays, strings, numbers, booleans, and malformed JSON (trailing commas, comments, unmatched quotes) all fail. The error carries fieldSelector '#pi-settings-config', so the form focuses the settings JSON editor after showing the inline error and toast.","triggerScenarios":"Submitting with the settings JSON editor containing '[]', '\"env\": {...}' fragments, a bare string/number, JSON5-style trailing commas or comments, or content left in an intermediate/broken typing state.","commonSituations":"Pasting an array of env vars instead of an object; hand-editing the JSON editor and saving mid-edit; importing a settings snippet whose outer braces were lost; assuming comments are allowed in the editor.","solutions":["Fix the JSON so it parses to a plain object, e.g. { \"apiKeyHelper\": \"/path/to/helper\" } instead of [...] or a bare primitive","Remove trailing commas, comments, and unquoted keys before saving","Pre-check with the same rule and disable Save: parseJsonObject(text) !== null","If settings are genuinely empty, keep the editor content as {}"],"exampleFix":"// before\nsettingsConfig: '[\"--flag\", \"--verbose\"]'\n\n// after\nsettingsConfig: '{ \"args\": [\"--flag\", \"--verbose\"] }'","handlingStrategy":"validation","validationCode":"function parsesAsJsonObject(value: string): boolean {\n  try {\n    const parsed: unknown = JSON.parse(value);\n    return !!parsed && typeof parsed === \"object\" && !Array.isArray(parsed);\n  } catch {\n    return false;\n  }\n}\n// gate submission:\nif (!parsesAsJsonObject(settingsConfig)) disableSave();","typeGuard":"function isJsonObjectText(value: string): value is string {\n  if (!parsesAsJsonObject(value)) return false;\n  return true;\n}","tryCatchPattern":"try {\n  await submit(identity);\n} catch (error) {\n  if (error instanceof Error && error.name === \"PiFormValidationError\" && error.message === t(\"jsonEditor.mustBeObject\")) {\n    focusSettingsEditor(); // equivalent of fieldSelector '#pi-settings-config'\n    return;\n  }\n  throw error;\n}","preventionTips":["Live-validate the JSON editor and disable Save while invalid","Auto-format the editor on blur so broken intermediate states never reach submit","Seed the editor with {} rather than empty text for new providers"],"tags":["form-validation","json","pi","provider"],"backgroundTag":null,"analyzedSha":"a2e22f330273a5b6ffa87cb8b82b624601bac562","analyzedAt":"2026-08-16T03:46:07.889Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}