{"record":{"id":"22ff28c805e14c6d","repo":"SillyTavern/SillyTavern","slug":"cannot-delete-yourself","errorCode":null,"errorMessage":"Cannot delete yourself","messagePattern":"Cannot delete yourself","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"public/scripts/user.js","lineNumber":350,"sourceCode":"        }\n\n        toastr.success('Password changed successfully', 'Password Changed');\n        callback();\n    } catch (error) {\n        console.error('Error changing password:', error);\n    }\n}\n\n/**\n * Delete a user.\n * @param {string} handle User handle\n * @param {function} callback Success callback\n */\nasync function deleteUser(handle, callback) {\n    try {\n        if (handle === currentUser.handle) {\n            toastr.error('Cannot delete yourself', 'Failed to delete user');\n            throw new Error('Cannot delete yourself');\n        }\n\n        let purge = false;\n        let confirmHandle = '';\n\n        const template = $(await renderTemplateAsync('deleteUser'));\n        template.find('#deleteUserName').text(handle);\n        template.find('input[name=\"deleteUserData\"]').on('input', function () {\n            purge = $(this).is(':checked');\n        });\n        template.find('input[name=\"deleteUserHandle\"]').on('input', function () {\n            confirmHandle = String($(this).val());\n        });\n\n        const result = await callGenericPopup(template, POPUP_TYPE.CONFIRM, '', { okButton: 'Delete', cancelButton: 'Cancel', wide: false, large: false });\n\n        if (result !== POPUP_RESULT.AFFIRMATIVE) {\n            throw new Error('Delete user cancelled');","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/SillyTavern/SillyTavern/blob/8172dcd0ee672d3cd9a5e5f7af134f91a45cd2b8/public/scripts/user.js#L332-L368","documentation":"Guard in `deleteUser` that prevents deleting the currently logged-in user (`handle === currentUser.handle`). It shows a toastr error and throws before any API call, so no request is sent.","triggerScenarios":"The user-management UI invokes `deleteUser` with the current user's own handle; a scripted batch deletion iterates over a list that includes the active account.","commonSituations":"Admin panel where the admin's own row exposes a delete button; bulk-delete script built from the user list without filtering self.","solutions":["Pass a handle different from `currentUser.handle`.","In the UI, disable or hide the delete action for the current user.","Filter the current user out of any batch before deletion."],"exampleFix":"// before\nfor (const h of handles) await deleteUser(h, cb);\n// after\nfor (const h of handles.filter(x => x !== currentUser.handle)) await deleteUser(h, cb);","handlingStrategy":"validation","validationCode":"if (handle === currentUser.handle) throw new Error('Cannot delete yourself');","typeGuard":"const isNotSelf = h => h !== currentUser.handle;","tryCatchPattern":null,"preventionTips":["Disable the delete control for the current user row.","Filter self out of batch operations."],"tags":["validation","user-management","guard"],"backgroundTag":null,"analyzedSha":"8172dcd0ee672d3cd9a5e5f7af134f91a45cd2b8","analyzedAt":"2026-08-13T07:48:40.832Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}