err:unkey:data:permission_already_exists
Example
What Happened?
This error occurs when you’re trying to create a permission with a name that already exists in your Unkey workspace. Permission names must be unique within a workspace to avoid confusion and maintain proper access control. Common scenarios that trigger this error:- Creating a permission with a name that’s already in use
- Re-creating a previously deleted permission with the same name
- Migration or import processes that don’t check for existing permissions
- Duplicate API calls due to retries or network issues
How To Fix
When you encounter this error, you have several options:- Use a different name: If creating a new permission, use a unique name
- Get the existing permission: If you just need the permission information, retrieve it rather than creating it
- List existing permissions: Check what permissions already exist before creating new ones
- Implement idempotent creation: Use a get-or-create pattern in your code
Common Mistakes
- Not checking for existing permissions: Failing to check if a permission already exists before creating it
- Case sensitivity: Permission names are case-insensitive - “Admin” and “admin” are the same
- Retry loops: Repeatedly trying to create the same permission after a failure
- Cross-environment duplication: Using the same permission names across development and production without proper namespacing
Related Errors
- err:unkey:data:permission_not_found - When the requested permission doesn’t exist
- err:unkey:authorization:insufficient_permissions - When you don’t have permission to manage permissions