{"record":{"id":"bd944eb13e2c4879","repo":"infiniflow/ragflow","slug":"flow-formattypeerror","errorCode":null,"errorMessage":"flow.formatTypeError","messagePattern":"flow\\.formatTypeError","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"web/src/pages/agent/gobal-variable-sheet/hooks/use-object-fields.tsx","lineNumber":102,"sourceCode":"        onChange={field.onChange}\n        height=\"400px\"\n        options={{\n          mode: 'code',\n          navigationBar: false,\n          mainMenuBar: true,\n          history: true,\n          onValidate: (json) => {\n            return validateKeys(json);\n          },\n        }}\n      />\n    );\n  }, []);\n\n  const objectValidate = useCallback((value: any) => {\n    try {\n      if (validateKeys(value, [])?.length > 0) {\n        throw new Error(t('flow.formatTypeError'));\n      }\n      if (!z.object({}).safeParse(value).success) {\n        throw new Error(t('flow.formatTypeError'));\n      }\n      if (value && typeof value === 'string' && !JSON.parse(value)) {\n        throw new Error(t('flow.formatTypeError'));\n      }\n      return true;\n    } catch (e) {\n      console.log('object-render-error', e, value);\n      throw new Error(t('flow.formatTypeError'));\n    }\n  }, []);\n\n  const arrayObjectValidate = useCallback((value: any) => {\n    try {\n      if (validateKeys(value, [])?.length > 0) {\n        throw new Error(t('flow.formatTypeError'));","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/web/src/pages/agent/gobal-variable-sheet/hooks/use-object-fields.tsx#L84-L120","documentation":"Thrown by objectValidate in the agent global-variable sheet (use-object-fields.tsx) when the value entered for an object-typed variable fails key validation. validateKeys(value, []) returns a non-empty error list, meaning the value is not a parseable object with valid keys. This is a react-hook-form field validator: the error message is the i18n key 'flow.formatTypeError' shown next to the input.","triggerScenarios":"User types an invalid JSON object (missing braces, trailing commas, single quotes) into an object-type global variable field; or the stored value is an array/string/null instead of an object; validateKeys returns error strings whose length > 0.","commonSituations":"Copy-pasting JSON with trailing commas or smart quotes from a doc; pre-existing variable value saved by an older RAGFlow version in a different shape; empty input treated as invalid because validateKeys does not accept undefined.","solutions":["Enter a syntactically valid JSON object, e.g. {\"key\": \"value\"}, in the variable field","If the value was pre-filled from saved state, clear the field and re-enter it — old saved values may have a stale shape","Check the console for the 'object-render-error' log which prints the offending value and the underlying parse error","If an empty object should be allowed, wrap the check: skip validation when value is undefined or empty string"],"exampleFix":"// before\nif (validateKeys(value, [])?.length > 0) {\n  throw new Error(t('flow.formatTypeError'));\n}\n\n// after\nconst isEmpty = value === undefined || value === null || value === '';\nif (!isEmpty && validateKeys(value, [])?.length > 0) {\n  throw new Error(t('flow.formatTypeError'));\n}","handlingStrategy":"validation","validationCode":"const isPlainObject = (v: unknown): v is Record<string, unknown> =>\n  typeof v === 'object' && v !== null && !Array.isArray(v);\n\nfunction tryParseObjectJson(v: unknown): Record<string, unknown> | null {\n  const parsed = typeof v === 'string' ? JSON.parse(v) as unknown : v;\n  return isPlainObject(parsed) ? parsed : null;\n}","typeGuard":"function isJsonObjectString(v: unknown): v is string {\n  if (typeof v !== 'string' || v.trim() === '') return false;\n  try { return isPlainObject(JSON.parse(v)); } catch { return false; }\n}","tryCatchPattern":"try {\n  objectValidate(value);\n} catch {\n  // react-hook-form field error; show inline, no rethrow\n  return { formatType: true }; // map to field error key instead of throwing","preventionTips":["Parse JSON editor output before it reaches the form value","Allow empty input explicitly if empty objects are valid for your flow","Use the console 'object-render-error' log to see the offending value when triaging"],"tags":["validation","json","agent","form","i18n"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}