{"record":{"id":"8670385634f72f41","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-settings","errorCode":"error-invalid-settings","errorMessage":"Invalid settings field","messagePattern":"Invalid settings field","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/autotranslate/functions/saveSettings.ts","lineNumber":26,"sourceCode":"export const saveAutoTranslateSettings = async (\n\tuserId: string,\n\trid: string,\n\tfield: string,\n\tvalue: string,\n\toptions: { defaultLanguage: string },\n) => {\n\tif (!(await hasPermissionAsync(userId, 'auto-translate'))) {\n\t\tthrow new Meteor.Error('error-action-not-allowed', 'Auto-Translate is not allowed', {\n\t\t\tmethod: 'autoTranslate.saveSettings',\n\t\t});\n\t}\n\n\tcheck(rid, String);\n\tcheck(field, String);\n\tcheck(value, String);\n\n\tif (['autoTranslate', 'autoTranslateLanguage'].indexOf(field) === -1) {\n\t\tthrow new Meteor.Error('error-invalid-settings', 'Invalid settings field', {\n\t\t\tmethod: 'saveAutoTranslateSettings',\n\t\t});\n\t}\n\n\tconst subscription = await Subscriptions.findOneByRoomIdAndUserId(rid, userId);\n\tif (!subscription) {\n\t\tthrow new Meteor.Error('error-invalid-subscription', 'Invalid subscription', {\n\t\t\tmethod: 'saveAutoTranslateSettings',\n\t\t});\n\t}\n\n\tlet shouldNotifySubscriptionChanged = false;\n\n\tswitch (field) {\n\t\tcase 'autoTranslate':\n\t\t\tconst room = await Rooms.findE2ERoomById(rid, { projection: { _id: 1 } });\n\t\t\tif (room && value === '1') {\n\t\t\t\tthrow new Meteor.Error('error-e2e-enabled', 'Enabling auto-translation in E2E encrypted rooms is not allowed', {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/autotranslate/functions/saveSettings.ts#L8-L44","documentation":"saveAutoTranslateSettings validates that `field` is one of exactly two strings: 'autoTranslate' (the on/off toggle, stored as '1'/'0') or 'autoTranslateLanguage' (the per-room target language code). Any other value throws error-invalid-settings. The REST body schema allows any string for field, so ajv does not stop it first.","triggerScenarios":"Calling autoTranslate.saveSettings with field='autoTranslateEnabled', 'language', or 'autoTranslate_Language'; sending a whole settings object instead of one field name; version skew where an older client sends a field name the server never knew.","commonSituations":"Hand-rolled API clients guessing field names; copy-paste from other settings methods; payloads built dynamically without a whitelist.","solutions":["Use only 'autoTranslate' or 'autoTranslateLanguage' as the field value","Type field as a string union on the caller so invalid values fail at compile time","Match the value shape: '1'/'0'-style string for autoTranslate, a language code for autoTranslateLanguage"],"exampleFix":"// before\ncall('autoTranslate.saveSettings', rid, 'autoTranslateEnabled', '1', opts); // error-invalid-settings\n\n// after\ncall('autoTranslate.saveSettings', rid, 'autoTranslate', '1', opts);","handlingStrategy":"type-guard","validationCode":"const ALLOWED = ['autoTranslate', 'autoTranslateLanguage'] as const;\nif (!ALLOWED.includes(field)) {\n  throw new TypeError(`field must be one of ${ALLOWED.join(', ')}`);\n}\nawait call('autoTranslate.saveSettings', rid, field, value, opts);","typeGuard":"type AutoTranslateField = 'autoTranslate' | 'autoTranslateLanguage';\nconst isAutoTranslateField = (f: string): f is AutoTranslateField =>\n  f === 'autoTranslate' || f === 'autoTranslateLanguage';","tryCatchPattern":"try {\n  await call('autoTranslate.saveSettings', rid, field, value, opts);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-settings') {\n    // fix the field name before retrying\n  } else {\n    throw e;\n  }\n}","preventionTips":["Type the field argument as a closed string union on the caller","Build payloads from a whitelist, never from dynamic user input","Send '1'/'0' style values for autoTranslate and language codes for autoTranslateLanguage"],"tags":["rocket-chat","autotranslate","validation","api-contract"],"backgroundTag":"invalid-argument-value","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}