{"record":{"id":"d6f212fd35838a5d","repo":"RocketChat/Rocket.Chat","slug":"error-duplicated-sla","errorCode":"error-duplicated-sla","errorMessage":"error-duplicated-sla","messagePattern":"error-duplicated-sla","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/lib/omnichannel/LivechatEnterprise.ts","lineNumber":160,"sourceCode":"\t},\n\n\tasync saveTag(_id: string | undefined, tagData: { name: string; description?: string }, tagDepartments: string[] | undefined) {\n\t\treturn LivechatTag.createOrUpdateTag(_id, tagData, tagDepartments);\n\t},\n\n\tasync saveSLA(\n\t\t_id: string | null,\n\t\tslaData: Pick<IOmnichannelServiceLevelAgreements, 'name' | 'description' | 'dueTimeInMinutes'>,\n\t\texecutedBy: string,\n\t) {\n\t\tconst oldSLA =\n\t\t\t_id &&\n\t\t\t(await OmnichannelServiceLevelAgreements.findOneById<Pick<IOmnichannelServiceLevelAgreements, 'dueTimeInMinutes'>>(_id, {\n\t\t\t\tprojection: { dueTimeInMinutes: 1 },\n\t\t\t}));\n\t\tconst exists = await OmnichannelServiceLevelAgreements.findDuplicate(_id, slaData.name, slaData.dueTimeInMinutes);\n\t\tif (exists) {\n\t\t\tthrow new Error('error-duplicated-sla');\n\t\t}\n\n\t\tconst sla = await OmnichannelServiceLevelAgreements.createOrUpdatePriority(slaData, _id);\n\t\tif (!oldSLA) {\n\t\t\treturn sla;\n\t\t}\n\n\t\tconst { dueTimeInMinutes: oldDueTimeInMinutes } = oldSLA;\n\t\tconst { dueTimeInMinutes } = sla;\n\n\t\tif (oldDueTimeInMinutes !== dueTimeInMinutes) {\n\t\t\tawait updateSLAInquiries(executedBy, sla);\n\t\t}\n\n\t\treturn sla;\n\t},\n\n\tasync removeSLA(executedBy: string, _id: string) {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/lib/omnichannel/LivechatEnterprise.ts#L142-L178","documentation":"Thrown by saveSLA in LivechatEnterprise.ts:160 when OmnichannelServiceLevelAgreements.findDuplicate(_id, name, dueTimeInMinutes) returns truthy, i.e. another SLA already has the same name or dueTimeInMinutes combination. NOTE: this uses `new Error('error-duplicated-sla')`, a plain Error, NOT a Meteor.Error — the code string is the message, so it does not carry a structured error code over the Meteor wire.","triggerScenarios":"Creating a new SLA whose name or dueTimeInMinutes collides with an existing one, or renaming/updating an SLA to a name already taken by a different _id. findDuplicate excludes the current _id, so collisions only flag *other* rows.","commonSituations":"Admin picks a duplicate SLA name; import/migration script creates SLAs with overlapping due times; UI does not pre-check uniqueness.","solutions":["Pick a unique name and a dueTimeInMinutes not already used by another SLA.","Pre-check with the SLA list endpoint before submitting the form.","Catch by message === 'error-duplicated-sla' (string match, since it is a plain Error)."],"exampleFix":"// before\nawait saveSLA(_id, { name, description, dueTimeInMinutes }, executedBy);\n\n// after\nconst dup = await OmnichannelServiceLevelAgreements.findDuplicate(_id, name, dueTimeInMinutes);\nif (dup) throw new Error('choose a unique SLA name/dueTime');\nawait saveSLA(_id, { name, description, dueTimeInMinutes }, executedBy);","handlingStrategy":"validation","validationCode":"const dup = await OmnichannelServiceLevelAgreements.findDuplicate(_id, name, dueTimeInMinutes);\nif (dup) throw new Error('SLA name/dueTime already used');","typeGuard":"const isSlaUnique = async (_id, name, dueTimeInMinutes) => !(await OmnichannelServiceLevelAgreements.findDuplicate(_id, name, dueTimeInMinutes));","tryCatchPattern":"try { await saveSLA(_id, slaData, executedBy); }\ncatch (e) {\n  if (e instanceof Error && e.message === 'error-duplicated-sla') { /* prompt unique name */ return; }\n  throw e;\n}","preventionTips":["Pre-check uniqueness before submitting the SLA form.","Maintain an SLA list cache to validate name client-side."],"tags":["omnichannel","sla","uniqueness","plain-error"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}