RocketChat/Rocket.Chat · warning · Meteor.Error

error-setting-validation-failed

error-setting-validation-failed

Error message

error.message

What it means

After type checks pass, `saveSetting` runs `validateSettingRules([{ _id, value }])`; a `SettingValidationError` is rethrown as `error-setting-validation-failed` with the rule's message. The message format is `<Setting_Id>_Invalid`, produced either by a `code: 'application/json'` setting whose value fails its JSON schema, or by the setting's declared `validation` rules — mongo-style filters (optionally gated by `appliesWhen` conditions and cross-setting `$setting` references) that reject the candidate value. Nothing is written when this throws.

Source

Thrown at apps/meteor/server/meteor-methods/settings/saveSetting.ts:77

			case 'roomPick':
				check(value, Match.OneOf([Object], ''));
				break;
			case 'boolean':
				check(value, Boolean);
				break;
			case 'int':
				check(value, Number);
				break;
			default:
				check(value, String);
				break;
		}

		try {
			validateSettingRules([{ _id, value }]);
		} catch (error) {
			if (error instanceof SettingValidationError) {
				throw new Meteor.Error('error-setting-validation-failed', error.message);
			}
			throw error;
		}

		const auditSettingOperation = updateAuditedByUser({
			_id: uid,
			username: (await Meteor.userAsync())!.username!,
			ip: this.connection?.clientAddress || '',
			useragent: this.connection?.httpHeaders['user-agent'] || '',
		});

		(await auditSettingOperation(Settings.updateValueAndEditorById, _id, value, editor)).modifiedCount &&
			setting &&
			void notifyOnSettingChanged({ ...setting, editor, value });

		return true;
	}),
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Read the embedded message: it is `<Setting_Id>_Invalid`, telling you exactly which setting rejected its value.
  2. For JSON settings, validate the payload with `JSON.parse` and the setting's schema before sending.
  3. Check the setting's `validation` rules (including `appliesWhen` and `$setting` references) and satisfy the filter's conditions, adjusting dependent settings in the same batch if needed.
  4. Empty string means 'unconfigured' and always passes — clearing the value is a valid escape hatch when you need to save something.

Example fix

// before - malformed JSON in an application/json setting -> '<Setting_Id>_Invalid'
Meteor.call('saveSetting', _id, '{ "enabled": true,}', editor);

// after - send schema-valid JSON (verify with JSON.parse first)
const value = JSON.stringify({ enabled: true });
JSON.parse(value); // throws locally before the server does
Meteor.call('saveSetting', _id, value, editor);
Defensive patterns

Strategy: try-catch

Validate before calling

// for JSON code settings, validate locally before sending
const isValidJsonSetting = (value: string): boolean => {
  if (value === '') return true; // empty = unconfigured, always passes
  try {
    JSON.parse(value);
    return true;
  } catch {
    return false;
  }
};

Type guard

const isSaveableJsonSetting = (value: string): boolean => value === '' || (() => { try { JSON.parse(value); return true; } catch { return false; } })();

Try / catch

try {
  await Meteor.callAsync('saveSetting', _id, value, editor);
} catch (e: any) {
  if (e?.error === 'error-setting-validation-failed') {
    // e.reason is '<Setting_Id>_Invalid': highlight that setting's field in the form
  }
}

Prevention

When it happens

Trigger: Calling `saveSetting` with a value the setting's validation rejects: invalid JSON in a `code: application/json` setting, or a value that does not satisfy the setting's `validation` filter while its `appliesWhen` conditions hold (including values cross-referenced from other settings in the same batch).

Common situations: Hand-editing JSON settings and leaving trailing commas; changing a value that other settings' validation rules depend on; copying setting values between workspaces whose validation rules differ; automation pushing a value that violates a conditional rule.

Understand the failure class

Background: Config validation failed: what "invalid value for {key}" and settings-rejection errors mean across 19 open-source libraries — this error's family across 19 libraries.

Related errors


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