{"record":{"id":"b83b5383b41133c8","repo":"alibaba/nacos","slug":"role-role-not-found","errorCode":null,"errorMessage":"role {role} not found!","messagePattern":"role (.+?) not found!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/roles/NacosRoleServiceDirectImpl.java","lineNumber":181,"sourceCode":"    \n    @Override\n    public void deleteRole(String role, String userName) {\n        rejectReservedRole(role);\n        rolePersistService.deleteRole(role, userName);\n        invalidateUserRoles(userName);\n    }\n    \n    @Override\n    public void deleteRole(String role) {\n        rejectReservedRole(role);\n        rolePersistService.deleteRole(role);\n        getCachedRoleInfoMap().remove(role);\n    }\n    \n    @Override\n    public void addPermission(String role, String resource, String action) {\n        if (!getCachedRoleSet().contains(role)) {\n            throw new IllegalArgumentException(\"role \" + role + \" not found!\");\n        }\n        permissionPersistService.addPermission(role, resource, action);\n        invalidateRolePermissions(role);\n    }\n    \n    @Override\n    public void deletePermission(String role, String resource, String action) {\n        permissionPersistService.deletePermission(role, resource, action);\n        invalidateRolePermissions(role);\n    }\n    \n    @Override\n    public Page<RoleInfo> findRoles(String username, String role, int pageNo, int pageSize) {\n        return rolePersistService.findRolesLike4Page(username, role, pageNo, pageSize);\n    }\n    \n    @Override\n    public List<String> findRoleNames(String role) {","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/roles/NacosRoleServiceDirectImpl.java#L163-L199","documentation":"Thrown by addPermission(role, resource, action) when the role is not present in the in-memory cachedRoleSet. Permissions can only be attached to roles that already exist, so the service validates role existence against the cache before persisting the permission. If the cache was not warmed, or the role was never created, the permission is rejected with IllegalArgumentException.","triggerScenarios":"POST /v3/admin/auth/permission for a role name that was never created; calling addPermission immediately after server start before the role cache is loaded; referencing a deleted role.","commonSituations":"Creating permissions before the role exists; cache not yet warmed on a freshly started node; role was created on another node and replication/cache-sync has not completed; typo in role name.","solutions":["Create the role first via roleService.addRole(role, username), then add permissions.","If the role should already exist, trigger a role-cache reload (or wait for sync) before retrying.","Verify the exact role name against getRoles before adding permissions."],"exampleFix":"// before\npermissionService.addPermission(\"ROLE_DEV\", \"/ns/**\", \"r\"); // role not in cache\n\n// after\nif (!roleService.getCachedRoleSet().contains(\"ROLE_DEV\")) {\n    roleService.addRole(\"ROLE_DEV\", ownerUsername);\n}\npermissionService.addPermission(\"ROLE_DEV\", \"/ns/**\", \"r\");","handlingStrategy":"validation","validationCode":"if (!roleService.getCachedRoleSet().contains(role)) {\n    throw new IllegalStateException(\"Cannot add permission: role '\" + role + \"' does not exist\");\n}\nroleService.addPermission(role, resource, action);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always create the role before attaching permissions to it.","After server start, wait for the role cache to load before granting permissions.","Verify role existence (exact name) before addPermission."],"tags":["auth","permission","role","validation","cache"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}