apache/shenyu · warning · ShenyuAdminException
The user namespace rel is exist!
Error message
The user namespace rel is exist!
What it means
ShenYu admin throws this when creating a namespace-user binding that already exists. NamespaceUserServiceImpl.create() first queries namespaceUserRelMapper.selectByNamespaceIdAndUserId(); if a row with the same (namespaceId, userId) pair is found, it aborts with ShenyuAdminException(AdminConstants.NAMESPACE_USER_EXIST) to keep the relation unique.
Solutions
- Check the existing relation first (list users of the namespace or query the namespace_user_rel table) and skip creation if it already exists.
- Make the create call idempotent on the caller side: catch ShenyuAdminException with message AdminConstants.NAMESPACE_USER_EXIST and treat it as success.
- If the binding is stale or wrong, delete the existing relation before re-creating it via the dashboard or delete API.
- Guard UI/forms against double submission (disable button until response).
Example fix
// before
namespaceUserService.create(namespaceId, userId);
// after
try {
namespaceUserService.create(namespaceId, userId);
} catch (ShenyuAdminException e) {
if (!AdminConstants.NAMESPACE_USER_EXIST.equals(e.getMessage())) {
throw e;
}
// already bound; treat as no-op
} Defensive patterns
Strategy: try-catch
Validate before calling
NamespaceUserRelDO existing = namespaceUserRelMapper.selectByNamespaceIdAndUserId(namespaceId, userId);
if (existing != null) { /* skip create or update instead */ } Try / catch
try {
namespaceUserService.create(namespaceId, userId);
} catch (ShenyuAdminException e) {
if (AdminConstants.NAMESPACE_USER_EXIST.equals(e.getMessage())) { /* idempotent no-op */ } else { throw e; }
} Prevention
- Check for an existing (namespaceId, userId) relation before calling create.
- Make client-side creation idempotent on this error.
- Disable submit buttons while a request is in flight to avoid double submits.
- Reconcile UI state with the DB after failed/retried requests.
When it happens
Trigger: Calling POST /namespaceUser (NamespaceUserController -> create -> onNamespaceCreated flow) with a namespaceId and userId that are already linked in the namespace_user_rel table; e.g. clicking 'add user to namespace' twice, or re-submitting a form after a timeout.
Common situations: Dashboard double-submit, retry after a slow request that actually succeeded, seeding scripts that run more than once, or admin UI state out of sync with the DB after manual row edits.
Understand the failure class
Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.
Related errors
- registry_id is already exist
- unique index conflict, please enter again
- namespaceId is null
- namespace is not exist
- dynamic: result.getMessage() from…
AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12).
Data as JSON: /api/errors/4b2a10c8ca1d542f.
Report an issue: GitHub.
Appendix: source
Thrown at shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceUserServiceImpl.java:50
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
public class NamespaceUserServiceImpl implements NamespaceUserService {
private final NamespaceUserRelMapper namespaceUserRelMapper;
public NamespaceUserServiceImpl(final NamespaceUserRelMapper namespaceUserRelMapper) {
this.namespaceUserRelMapper = namespaceUserRelMapper;
}
@Override
public NamespaceUserRelVO create(final String namespaceId, final String userId) {
NamespaceUserRelDO existNamespaceUserRelDO = namespaceUserRelMapper.selectByNamespaceIdAndUserId(namespaceId, userId);
if (!Objects.isNull(existNamespaceUserRelDO)) {
throw new ShenyuAdminException(AdminConstants.NAMESPACE_USER_EXIST);
}
String uuid = UUIDUtils.getInstance().generateShortUuid();
NamespaceUserRelDO namespaceUserRelDO = NamespaceUserRelDO.builder()
.id(uuid)
.namespaceId(namespaceId)
.userId(userId)
.build();
namespaceUserRelMapper.insertSelective(namespaceUserRelDO);
return NamespaceUserRelVO.builder()
.id(uuid)
.namespaceId(namespaceId)
.userId(userId)
.build();
}
@Override
public List<String> listNamespaceIdByUserId(final String userId) {View on GitHub (pinned to 567142e072)