{"record":{"id":"28ec33ed3fef1e37","repo":"RocketChat/Rocket.Chat","slug":"error-setting-validation-failed-28ec33","errorCode":"error-setting-validation-failed","errorMessage":"error.message","messagePattern":"error\\.message","errorType":"validation","errorClass":"Meteor.Error","httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/meteor-methods/settings/saveSetting.ts","lineNumber":77,"sourceCode":"\t\t\tcase 'roomPick':\n\t\t\t\tcheck(value, Match.OneOf([Object], ''));\n\t\t\t\tbreak;\n\t\t\tcase 'boolean':\n\t\t\t\tcheck(value, Boolean);\n\t\t\t\tbreak;\n\t\t\tcase 'int':\n\t\t\t\tcheck(value, Number);\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tcheck(value, String);\n\t\t\t\tbreak;\n\t\t}\n\n\t\ttry {\n\t\t\tvalidateSettingRules([{ _id, value }]);\n\t\t} catch (error) {\n\t\t\tif (error instanceof SettingValidationError) {\n\t\t\t\tthrow new Meteor.Error('error-setting-validation-failed', error.message);\n\t\t\t}\n\t\t\tthrow error;\n\t\t}\n\n\t\tconst auditSettingOperation = updateAuditedByUser({\n\t\t\t_id: uid,\n\t\t\tusername: (await Meteor.userAsync())!.username!,\n\t\t\tip: this.connection?.clientAddress || '',\n\t\t\tuseragent: this.connection?.httpHeaders['user-agent'] || '',\n\t\t});\n\n\t\t(await auditSettingOperation(Settings.updateValueAndEditorById, _id, value, editor)).modifiedCount &&\n\t\t\tsetting &&\n\t\t\tvoid notifyOnSettingChanged({ ...setting, editor, value });\n\n\t\treturn true;\n\t}),\n});","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/settings/saveSetting.ts#L59-L95","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Read the embedded message: it is `<Setting_Id>_Invalid`, telling you exactly which setting rejected its value.","For JSON settings, validate the payload with `JSON.parse` and the setting's schema before sending.","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.","Empty string means 'unconfigured' and always passes — clearing the value is a valid escape hatch when you need to save something."],"exampleFix":"// before - malformed JSON in an application/json setting -> '<Setting_Id>_Invalid'\nMeteor.call('saveSetting', _id, '{ \"enabled\": true,}', editor);\n\n// after - send schema-valid JSON (verify with JSON.parse first)\nconst value = JSON.stringify({ enabled: true });\nJSON.parse(value); // throws locally before the server does\nMeteor.call('saveSetting', _id, value, editor);","handlingStrategy":"try-catch","validationCode":"// for JSON code settings, validate locally before sending\nconst isValidJsonSetting = (value: string): boolean => {\n  if (value === '') return true; // empty = unconfigured, always passes\n  try {\n    JSON.parse(value);\n    return true;\n  } catch {\n    return false;\n  }\n};","typeGuard":"const isSaveableJsonSetting = (value: string): boolean => value === '' || (() => { try { JSON.parse(value); return true; } catch { return false; } })();","tryCatchPattern":"try {\n  await Meteor.callAsync('saveSetting', _id, value, editor);\n} catch (e: any) {\n  if (e?.error === 'error-setting-validation-failed') {\n    // e.reason is '<Setting_Id>_Invalid': highlight that setting's field in the form\n  }\n}","preventionTips":["Parse JSON settings client-side before saving so failures surface early.","Learn each setting's validation rules (including appliesWhen dependencies) before scripting value changes.","Remember empty string is the safe 'unconfigured' value when a setting cannot be satisfied."],"tags":["meteor","settings","validation","json-schema"],"backgroundTag":"config-validation-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}