apache/shenyu · error · ShenyuException

shenyu this discovery is not found in current namespace

Error message

shenyu this discovery is not found in current namespace

What it means

Thrown by DiscoveryServiceImpl.delete when the discovery record for the given discoveryId does not exist in the database, or exists but its namespaceId does not match the namespaceId passed to the call. The admin layer enforces namespace isolation: a discovery configuration may only be removed from the namespace it belongs to.

Solutions

  1. Verify discoveryId exists via GET /discovery/list in the target namespace before deleting
  2. Confirm the namespaceId query/header used matches the namespace the discovery was created in
  3. Refresh the dashboard/re-fetch the list to clear stale ids and retry
  4. If legacy rows lack the correct namespace_id, fix the row in the discovery table instead of retrying the delete

Example fix

// before
discoveryService.delete(discoveryId, namespaceId);
// after
DiscoveryVO vo = discoveryService.findByDiscoveryId(discoveryId);
if (vo != null && namespaceId.equals(vo.getNamespaceId())) {
    discoveryService.delete(discoveryId, namespaceId);
}
Defensive patterns

Strategy: validation

Validate before calling

DiscoveryDO d = discoveryMapper.selectById(discoveryId);
if (d == null || !namespaceId.equals(d.getNamespaceId())) {
    throw new IllegalStateException("discovery " + discoveryId + " not in namespace " + namespaceId);
}

Try / catch

try {
    discoveryService.delete(discoveryId, namespaceId);
} catch (ShenyuException e) {
    if (e.getMessage().contains("not found in current namespace")) {
        LOG.warn("skip: discovery {} not in namespace {}", discoveryId, namespaceId);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling DELETE /discovery (DiscoveryServiceImpl.delete) with a discoveryId that was already deleted, that was never created, or with a namespaceId different from the one the discovery was created under (e.g. after switching the dashboard to another namespace or passing a stale/default namespace id).

Common situations: Stale UI state after another operator deleted the discovery; mixing namespace ids when scripting the admin REST API; multi-namespace setups where the discovery was created in a different namespace; upgrading ShenYu versions that introduced namespace scoping to legacy data.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/030d666258a610f4. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java:201

            discoveryHandlerMapper.insertSelective(discoveryHandlerDO);
        }
        DiscoveryProcessor discoveryProcessor = discoveryProcessorHolder.chooseProcessor(discoveryConfigRegisterDTO.getDiscoveryType());
        discoveryProcessor.createDiscovery(discoveryDO);
        discoveryProcessor.createProxySelector(DiscoveryTransfer.INSTANCE.mapToDTO(discoveryHandlerDO), proxySelectorDTO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String delete(final String discoveryId, final String namespaceId) {
        List<DiscoveryHandlerDO> discoveryHandlerDOS = discoveryHandlerMapper.selectByDiscoveryId(discoveryId);
        if (CollectionUtils.isNotEmpty(discoveryHandlerDOS)) {
            LOG.warn("shenyu this discovery has discoveryHandler can't be delete");
            throw new ShenyuException("shenyu this discovery has discoveryHandler can't be delete");
        }
        DiscoveryDO discoveryDO = discoveryMapper.selectById(discoveryId);
        if (Objects.isNull(discoveryDO) || !Objects.equals(discoveryDO.getNamespaceId(), namespaceId)) {
            LOG.warn("shenyu discovery {} is not found in namespace {}", discoveryId, namespaceId);
            throw new ShenyuException("shenyu this discovery is not found in current namespace");
        }
        DiscoveryProcessor discoveryProcessor = discoveryProcessorHolder.chooseProcessor(discoveryDO.getDiscoveryType());
        discoveryProcessor.removeDiscovery(discoveryDO);
        discoveryMapper.delete(discoveryId, namespaceId);
        return ShenyuResultMessage.DELETE_SUCCESS;
    }

    private DiscoveryVO create(final DiscoveryDTO discoveryDTO) {
        if (Objects.isNull(discoveryDTO)) {
            return null;
        }
        Timestamp currentTime = new Timestamp(System.currentTimeMillis());
        DiscoveryDO discoveryDO = DiscoveryDO.builder()
                .id(discoveryDTO.getId())
                .discoveryName(discoveryDTO.getName())
                .pluginName(discoveryDTO.getPluginName())
                .namespaceId(discoveryDTO.getNamespaceId())
                .discoveryType(discoveryDTO.getType())

View on GitHub (pinned to 567142e072)