{"record":{"id":"f1f695e03773d9e5","repo":"RocketChat/Rocket.Chat","slug":"duplicated-account","errorCode":"duplicated-account","errorMessage":"Account not found","messagePattern":"Account not found","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/bridges/webdav/methods/addWebdavAccount.ts","lineNumber":110,"sourceCode":"\t\t}\n\n\t\tcheck(\n\t\t\tformData,\n\t\t\tMatch.ObjectIncluding({\n\t\t\t\tserverURL: String,\n\t\t\t\tusername: String,\n\t\t\t\tpassword: String,\n\t\t\t\tname: Match.Maybe(String),\n\t\t\t}),\n\t\t);\n\n\t\tconst duplicateAccount = await WebdavAccounts.findOneByUserIdServerUrlAndUsername(\n\t\t\t{ userId, serverURL: formData.serverURL, username: formData.username },\n\t\t\t{},\n\t\t);\n\n\t\tif (duplicateAccount !== null) {\n\t\t\tthrow new Meteor.Error('duplicated-account', 'Account not found', {\n\t\t\t\tmethod: 'addWebdavAccount',\n\t\t\t});\n\t\t}\n\n\t\ttry {\n\t\t\tconst client = new WebdavClientAdapter(formData.serverURL, {\n\t\t\t\tusername: formData.username,\n\t\t\t\tpassword: formData.password,\n\t\t\t});\n\n\t\t\tconst accountData = {\n\t\t\t\tuserId,\n\t\t\t\tserverURL: formData.serverURL,\n\t\t\t\tusername: formData.username,\n\t\t\t\tpassword: formData.password,\n\t\t\t\tname: formData.name ?? '',\n\t\t\t};\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/bridges/webdav/methods/addWebdavAccount.ts#L92-L128","documentation":"Thrown when WebdavAccounts.findOneByUserIdServerUrlAndUsername finds an existing account with the same userId, serverURL, and username. Note the confusing mismatch: the error code is 'duplicated-account' but the human message reads 'Account not found' — the actual condition is the opposite, a duplicate. Client code must branch on the code, not the message.","triggerScenarios":"Submitting the addWebdavAccount form with the same serverURL + username combination the user already saved (for example, re-submitting the form after a partial success, or adding the same box twice).","commonSituations":"Users double-submitting the account form; retrying after a confusing first error and hitting the duplicate guard; UI not surfacing already-connected accounts, so the user re-adds an existing one.","solutions":["Remove the existing account first (Account settings / WebDAV accounts list), then re-add it","Change the username or serverURL if you genuinely need a second account on the same server","Match on err.error === 'duplicated-account', not the misleading 'Account not found' message","Pre-check the accounts list in the UI before enabling submit"],"exampleFix":"// before\nawait call('addWebdavAccount', formData); // throws duplicated-account ('Account not found')\n\n// after — dedupe in the UI first\nconst dup = accounts.some((a) => a.serverURL === formData.serverURL && a.username === formData.username);\nif (dup) { showToast('Account already connected'); return; }\nawait call('addWebdavAccount', formData);","handlingStrategy":"validation","validationCode":"const dup = accounts.some(\n  (a) => a.serverURL === formData.serverURL && a.username === formData.username,\n);\nif (dup) {\n  showToast('This WebDAV account is already connected');\n  return;\n}\nawait call('addWebdavAccount', formData);","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('addWebdavAccount', formData);\n} catch (e) {\n  if (e.error === 'duplicated-account') {\n    // note: the message misleadingly says 'Account not found';\n    // offer to remove the existing account and re-add\n  }\n}","preventionTips":["Branch on the error code 'duplicated-account', never on its message","Dedupe serverURL+username in the form before submit","Disable double-submits while the method call is in flight"],"tags":["webdav","meteor","duplicate","validation"],"backgroundTag":"duplicate-record","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}