{"record":{"id":"63052cb9eeb08311","repo":"RocketChat/Rocket.Chat","slug":"error-validating-department-chat-closing-tags","errorCode":"error-validating-department-chat-closing-tags","errorMessage":"At least one closing tag is required when the department requires tag(s) on closing conversations.","messagePattern":"At least one closing tag is required when the department requires tag\\(s\\) on closing conversations\\.","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/omnichannel/departmentsLib.ts","lineNumber":96,"sourceCode":"\t// The Livechat Form department support addition/custom fields, so those fields need to be added before validating\n\tObject.keys(departmentData).forEach((field) => {\n\t\tif (!defaultValidations.hasOwnProperty(field)) {\n\t\t\tdefaultValidations[field] = Match.OneOf(String, Match.Integer, Boolean);\n\t\t}\n\t});\n\n\tcheck(departmentData, defaultValidations);\n\tcheck(\n\t\tdepartmentAgents,\n\t\tMatch.Maybe({\n\t\t\tupsert: Match.Maybe(Array),\n\t\t\tremove: Match.Maybe(Array),\n\t\t}),\n\t);\n\n\tconst { requestTagBeforeClosingChat, chatClosingTags, fallbackForwardDepartment } = departmentData;\n\tif (requestTagBeforeClosingChat && (!chatClosingTags || chatClosingTags.length === 0)) {\n\t\tthrow new Meteor.Error(\n\t\t\t'error-validating-department-chat-closing-tags',\n\t\t\t'At least one closing tag is required when the department requires tag(s) on closing conversations.',\n\t\t\t{ method: 'livechat:saveDepartment' },\n\t\t);\n\t}\n\n\tif (_id && !department) {\n\t\tthrow new Meteor.Error('error-department-not-found', 'Department not found', {\n\t\t\tmethod: 'livechat:saveDepartment',\n\t\t});\n\t}\n\n\tif (fallbackForwardDepartment === _id) {\n\t\tthrow new Meteor.Error(\n\t\t\t'error-fallback-department-circular',\n\t\t\t'Cannot save department. Circular reference between fallback department and department',\n\t\t);\n\t}","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/omnichannel/departmentsLib.ts#L78-L114","documentation":"Thrown by `livechat:saveDepartment` after the `check(departmentData, defaultValidations)` stage when `requestTagBeforeClosingChat` is truthy but `chatClosingTags` is missing, undefined, or an empty array. Closing tags are conditionally required: enabling 'require tag before closing chat' demands at least one selectable tag.","triggerScenarios":"Saving a department whose payload has `requestTagBeforeClosingChat: true` while `chatClosingTags` is absent, `[]`, or falsy — typically a form that lets agents toggle the 'require tags' switch without seeding the tag picker.","commonSituations":"New department forms where the closing-tags input is optional and left empty; API integrations that copy a template department and strip the tags array; toggling the setting on an existing department that never had tags.","solutions":["Provide at least one tag: `chatClosingTags: ['billing-issue']` in the departmentData payload","Or keep `requestTagBeforeClosingChat: false` until tags are configured","Add client-side form validation tying the 'require closing tags' switch to a non-empty tags list before calling the method"],"exampleFix":"// before\nawait saveDepartment(_id, { ...deptData, requestTagBeforeClosingChat: true }); // chatClosingTags missing\n\n// after\nawait saveDepartment(_id, {\n  ...deptData,\n  requestTagBeforeClosingChat: true,\n  chatClosingTags: deptData.chatClosingTags?.length ? deptData.chatClosingTags : ['support'],\n});","handlingStrategy":"validation","validationCode":"if (deptData.requestTagBeforeClosingChat && !deptData.chatClosingTags?.length) {\n  throw new Error('Provide at least one closing tag or disable the requirement');\n}\nawait saveDepartment(_id, deptData);","typeGuard":"const hasRequiredClosingTags = (d: { requestTagBeforeClosingChat?: boolean; chatClosingTags?: string[] }): boolean =>\n  !d.requestTagBeforeClosingChat || (d.chatClosingTags?.length ?? 0) > 0;","tryCatchPattern":"try {\n  await saveDepartment(_id, deptData);\n} catch (e) {\n  if (isMeteorError(e, 'error-validating-department-chat-closing-tags')) {\n    // prompt user to add chatClosingTags or turn off requestTagBeforeClosingChat\n  }\n}","preventionTips":["Link the 'require closing tags' switch to non-empty tag input in the form","Validate conditionally-required pairs before any saveDepartment call","Seed default tags when enabling the requirement programmatically"],"tags":["omnichannel","departments","validation","closing-tags","livechat"],"backgroundTag":"conditionally-required-field-missing","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"}