{"record":{"id":"e7dbb0dace373bcf","repo":"RocketChat/Rocket.Chat","slug":"error-duplicate-channel-name","errorCode":"error-duplicate-channel-name","errorMessage":"A channel with name '${cleanName}' exists","messagePattern":"A channel with name '(.+?)' exists","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/utils/lib/getValidRoomName.ts","lineNumber":23,"sourceCode":"\nimport { settings } from '../../../settings';\nimport { validateName } from '../../shared/validateName';\n\nexport const getValidRoomName = async (displayName: string, rid = '', options: { allowDuplicates?: boolean } = {}) => {\n\tlet slugifiedName = displayName;\n\n\tif (settings.get('UI_Allow_room_names_with_special_chars')) {\n\t\tconst cleanName = limax(displayName, { maintainCase: true });\n\t\tif (options.allowDuplicates !== true) {\n\t\t\tconst room = await Rooms.findOneByDisplayName(displayName);\n\t\t\tif (room && room._id !== rid) {\n\t\t\t\tif (room.archived) {\n\t\t\t\t\tthrow new Meteor.Error('error-archived-duplicate-name', `There's an archived channel with name ${cleanName}`, {\n\t\t\t\t\t\tfunction: 'RocketChat.getValidRoomName',\n\t\t\t\t\t\tchannel_name: cleanName,\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\tthrow new Meteor.Error('error-duplicate-channel-name', `A channel with name '${cleanName}' exists`, {\n\t\t\t\t\t\tfunction: 'RocketChat.getValidRoomName',\n\t\t\t\t\t\tchannel_name: cleanName,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tslugifiedName = cleanName;\n\t}\n\n\tlet nameValidation;\n\n\ttry {\n\t\tnameValidation = new RegExp(`^${settings.get('UTF8_Channel_Names_Validation')}$`);\n\t} catch (error) {\n\t\tnameValidation = new RegExp('^[0-9a-zA-Z-_.]+$');\n\t}\n\n\tif (!nameValidation.test(slugifiedName) || !validateName(slugifiedName)) {","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/utils/lib/getValidRoomName.ts#L5-L41","documentation":"Same special-chars path as its archived sibling, but the conflicting room (same display name, different _id) is live, so creation/rename is refused with error-duplicate-channel-name. Contrast the lower branch of the same function: in the non-special-chars path Rocket.Chat auto-appends -2, -3… suffixes instead of throwing — throwing on duplicates only happens for display-name matches when UI_Allow_room_names_with_special_chars is on.","triggerScenarios":"Creating or renaming a channel to the display name of an active channel (UI_Allow_room_names_with_special_chars on, allowDuplicates !== true).","commonSituations":"Common channel names ('general', 'random', 'announcements'); parallel departments naming channels identically; imports colliding with existing rooms.","solutions":["Choose a different display name","Pass { allowDuplicates: true } when the caller's semantics allow same display names (slugs still differ)","Rename or delete the existing live channel first if consolidation is intended"],"exampleFix":"// before\nawait getValidRoomName('general'); // live channel named 'general' exists\n\n// after\nawait getValidRoomName('general', '', { allowDuplicates: true });\n// or pick a distinct name\nawait getValidRoomName('general-eng');","handlingStrategy":"validation","validationCode":"import { Rooms } from '@rocket.chat/models';\n\nconst existing = await Rooms.findOneByDisplayName(displayName);\nif (existing && existing._id !== rid && !existing.archived) {\n  // name taken by a live room: block or suggest alternatives\n}","typeGuard":null,"tryCatchPattern":"try {\n  await getValidRoomName(name, rid);\n} catch (error) {\n  if (error instanceof Meteor.Error && error.error === 'error-duplicate-channel-name') {\n    // suggest name variants (name-2, name-team)\n  } else {\n    throw error;\n  }\n}","preventionTips":["Pre-check display-name availability while the user types the channel name","Consider allowDuplicates: true for workspaces that key rooms by slug, not display name","Distinguish archived vs live duplicates in UI messaging — the remedies differ"],"tags":["rooms","duplicate","channel-name","meteor"],"backgroundTag":"duplicate-room-name","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}