RocketChat/Rocket.Chat · error · Error

Invalid custom fields config

Error message

Invalid custom fields config

What it means

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.

Source

Thrown at apps/meteor/server/lib/messaging/validateCustomMessageFields.ts:9

import { ajv } from '@rocket.chat/rest-typings';
import mem from 'mem';

const customFieldsValidate = mem(
	(customFieldsSetting: string) => {
		const schema = JSON.parse(customFieldsSetting);

		if (schema.type && schema.type !== 'object') {
			throw new Error('Invalid custom fields config');
		}

		return ajv.compile({
			...schema,
			type: 'object',
			additionalProperties: false,
		});
	},
	{ maxAge: 1000 * 60 },
);

export const validateCustomMessageFields = ({
	customFields,
	messageCustomFieldsEnabled,
	messageCustomFields,
}: {
	customFields: Record<string, any>;
	messageCustomFieldsEnabled: boolean;

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Set Message_CustomFields to an object schema: { "type": "object", "properties": { ... }, "additionalProperties": false }
  2. Omit the type key entirely - the compiler injects type: 'object' anyway
  3. Dry-run the JSON with JSON.parse and an ajv compile before saving the setting
  4. Remember the 60s memoization: wait or restart before retesting

Example fix

// before (Admin -> Message_CustomFields)
{ "type": "array", "items": { "type": "string" } }

// after
{ "type": "object", "properties": { "ticketId": { "type": "string" } }, "additionalProperties": false }
Defensive patterns

Strategy: validation

Validate before calling

// Verify an admin-provided schema before saving/using it
const checkSchemaConfig = (raw: string): void => {
  const schema = JSON.parse(raw); // throws SyntaxError if malformed
  if (schema.type && schema.type !== 'object') {
    throw new Error('Invalid custom fields config');
  }
  ajv.compile({ ...schema, type: 'object', additionalProperties: false }); // dry-run
};

Type guard

const isObjectSchema = (s: { type?: string }): boolean => !s.type || s.type === 'object';

Try / catch

try {
  await sendMessage(user, message, room);
} catch (e) {
  if (e instanceof Error && e.message === 'Invalid custom fields config') {
    disableCustomFieldsAndAlertAdmin(); // config-level failure: block sends, surface to admin
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/868916b39bc14a1f. Report an issue: GitHub.