iflytek/astron-agent · warning · BusinessException

DATABASE_NAME_EXIST

DATABASE_NAME_EXIST

Error message

DATABASE_NAME_EXIST

What it means

Thrown by DatabaseService.create when a database with the same name already exists for the current user and space (deleted=false). The service counts existing DbInfo rows matching name+uid+spaceId before creating, and refuses duplicates. It is a uniqueness-constraint violation surfaced as a business error.

Solutions

  1. Query the existing database list first and reuse or rename before calling create
  2. Choose a unique name (append suffix/timestamp)
  3. If the old one is stale, delete it (soft delete) and retry
  4. Handle this error in the UI and prompt the user for a new name

Example fix

// before
DatabaseDto dto = new DatabaseDto();
dto.setName("my-db"); // may already exist
databaseService.create(dto);
// after
dto.setName("my-db-" + System.currentTimeMillis());
databaseService.create(dto);
Defensive patterns

Strategy: validation

Validate before calling

Long dup = dbInfoMapper.selectCount(new QueryWrapper<DbInfo>().lambda()
    .eq(DbInfo::getName, name).eq(DbInfo::getUid, userId).eq(DbInfo::getSpaceId, spaceId).eq(DbInfo::getDeleted, false));
if (dup > 0) { /* rename or reuse */ }

Try / catch

try { databaseService.create(dto); } catch (BusinessException e) { if ("DATABASE_NAME_EXIST".equals(e.getCode())) { dto.setName(dto.getName() + "-" + suffix); retry once; } else { throw e; } }

Prevention

When it happens

Trigger: Calling create with a name that already matches an existing non-deleted DbInfo record belonging to the same userId and spaceId.

Common situations: User clicks 'create' twice on the same form; retry after a timeout actually created the first record; migrating/importing databases whose names collide; test fixtures reusing fixed names without cleanup.

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


AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12). Data as JSON: /api/errors/bdf61b3f138a2650. Report an issue: GitHub.

Appendix: source

Thrown at console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java:127

            String userId = Objects.requireNonNull(UserInfoManagerHandler.getUserId()).toString();
            Long spaceId = SpaceInfoUtil.getSpaceId();
            // Duplicate name validation
            Long count = 0L;
            if (spaceId == null) {
                count = dbInfoMapper.selectCount(new QueryWrapper<DbInfo>().lambda()
                        .eq(DbInfo::getName, databaseDto.getName())
                        .eq(DbInfo::getSpaceId, null)
                        .eq(DbInfo::getUid, userId)
                        .eq(DbInfo::getDeleted, false));
            } else {
                count = dbInfoMapper.selectCount(new QueryWrapper<DbInfo>().lambda()
                        .eq(DbInfo::getName, databaseDto.getName())
                        .eq(DbInfo::getUid, userId)
                        .eq(DbInfo::getSpaceId, spaceId)
                        .eq(DbInfo::getDeleted, false));
            }
            if (count > 0) {
                throw new BusinessException(ResponseEnum.DATABASE_NAME_EXIST);
            }
            // Call core system to create database
            Long dbId = coreSystemService.createDatabase(databaseDto.getName(), userId, spaceId, databaseDto.getDescription());
            // Save record
            DbInfo database = new DbInfo();
            BeanUtils.copyProperties(databaseDto, database);
            database.setUid(userId);
            database.setAppId(commonConfig.getAppId());
            database.setDbId(dbId);
            database.setCreateTime(new Date());
            database.setUpdateTime(new Date());
            database.setSpaceId(spaceId);
            dbInfoMapper.insert(database);
            return database;
        } catch (Exception ex) {
            log.info("Failed to create database, params:{}", databaseDto.toString(), ex);
            throw new BusinessException(ResponseEnum.DATABASE_CREATE_FAILED);
        }

View on GitHub (pinned to 5e758547a8)