{"record":{"id":"868916b39bc14a1f","repo":"RocketChat/Rocket.Chat","slug":"invalid-custom-fields-config","errorCode":null,"errorMessage":"Invalid custom fields config","messagePattern":"Invalid custom fields config","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/messaging/validateCustomMessageFields.ts","lineNumber":9,"sourceCode":"import { ajv } from '@rocket.chat/rest-typings';\nimport mem from 'mem';\n\nconst customFieldsValidate = mem(\n\t(customFieldsSetting: string) => {\n\t\tconst schema = JSON.parse(customFieldsSetting);\n\n\t\tif (schema.type && schema.type !== 'object') {\n\t\t\tthrow new Error('Invalid custom fields config');\n\t\t}\n\n\t\treturn ajv.compile({\n\t\t\t...schema,\n\t\t\ttype: 'object',\n\t\t\tadditionalProperties: false,\n\t\t});\n\t},\n\t{ maxAge: 1000 * 60 },\n);\n\nexport const validateCustomMessageFields = ({\n\tcustomFields,\n\tmessageCustomFieldsEnabled,\n\tmessageCustomFields,\n}: {\n\tcustomFields: Record<string, any>;\n\tmessageCustomFieldsEnabled: boolean;","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/messaging/validateCustomMessageFields.ts#L1-L27","documentation":"validateCustomMessageFields compiles the workspace's Message_CustomFields setting (a JSON-Schema string) with ajv, forcing type 'object' and additionalProperties false. It throws a plain Error 'Invalid custom fields config' when the parsed schema declares a type other than 'object'. The compiled validator is memoized for 60 seconds (mem maxAge), so a corrected setting can take up to a minute to take effect.","triggerScenarios":"An admin saves Message_CustomFields as a schema whose type is 'array', 'string', etc.; the next sendMessage or updateMessage that carries customFields parses the setting and this compile step throws. Malformed JSON additionally fails earlier at JSON.parse with a SyntaxError.","commonSituations":"Copy-pasting a schema intended for another system; not realizing the setting must be a JSON-Schema object; testing a fix and being confused by the 60-second validator cache.","solutions":["Set Message_CustomFields to an object schema: { \"type\": \"object\", \"properties\": { ... }, \"additionalProperties\": false }","Omit the type key entirely - the compiler injects type: 'object' anyway","Dry-run the JSON with JSON.parse and an ajv compile before saving the setting","Remember the 60s memoization: wait or restart before retesting"],"exampleFix":"// before (Admin -> Message_CustomFields)\n{ \"type\": \"array\", \"items\": { \"type\": \"string\" } }\n\n// after\n{ \"type\": \"object\", \"properties\": { \"ticketId\": { \"type\": \"string\" } }, \"additionalProperties\": false }","handlingStrategy":"validation","validationCode":"// Verify an admin-provided schema before saving/using it\nconst checkSchemaConfig = (raw: string): void => {\n  const schema = JSON.parse(raw); // throws SyntaxError if malformed\n  if (schema.type && schema.type !== 'object') {\n    throw new Error('Invalid custom fields config');\n  }\n  ajv.compile({ ...schema, type: 'object', additionalProperties: false }); // dry-run\n};","typeGuard":"const isObjectSchema = (s: { type?: string }): boolean => !s.type || s.type === 'object';","tryCatchPattern":"try {\n  await sendMessage(user, message, room);\n} catch (e) {\n  if (e instanceof Error && e.message === 'Invalid custom fields config') {\n    disableCustomFieldsAndAlertAdmin(); // config-level failure: block sends, surface to admin\n  }\n}","preventionTips":["Treat Message_CustomFields as a JSON Schema document and lint it on save","Reject type values other than 'object' in admin UI validation before persisting","Remember the 60-second validator cache when verifying a fix"],"tags":["custom-fields","json-schema","settings","ajv"],"backgroundTag":"invalid-json-schema-config","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}